CSS3实现炫酷进度条

看了一个进度条很漂亮,所以自己试试看


html

<div class="load-container">
		<span class="run"></span>
		<div class="meter">0</div>
	</div>


css样式:

* {
			margin: 0;
			padding: 0;
			font-family: 'microsoft yahei';
		}
		html,body {
			width: 100%;
			height: 100%;
			background-color: #222;
		}
		.load-container {
			width: 600px;
			height: 6px;
			margin: 0 auto;
			margin-top: 200px;
			background-image: -webkit-linear-gradient(left,#5bd8ff, #ff0000);
			border-radius: 5px;
			position: relative;
		}
		.run {
			position: absolute;
    		width: 0px;
    		height: 6px;
    		right: 0px;
    		background: #000;
    		border-radius: 5px;
    		animation: runnAnimation 10s linear;
		}
		@keyframes runnAnimation {
			0% {
				width: 600px;
			}
			100% {
				width: 0px;
			}
		}
		.run:after {
			content: "";
			display: block;
			width: 16px;
			height: 16px;
			border-radius: 50%;
			background-color: #f00;
			margin-left: -4px;
			margin-top: -4px;
			animation: destination 10s linear;
		}
		@keyframes destination {
			0% {
				background-color: #5bd8ff;
			}
			100% {
				background-color: red;
			}
		}
		.meter {
			float: right;
			margin-top: 10px;
    		font-size: 40px;
    		color: red;
    		animation: fontColor 10s linear;
		}
		@keyframes fontColor {
			0% {
				color: #5bd8ff;
			}
			100% {
				color: red;
			}
		}
		.meter:after {
			content: "%"
		}

js代码如下:

window.onload = function() {
			var meter = document.querySelector('.meter');
			run(meter,100);

			function run(el,time) {
				time = time ? time : 100;
				el = el ? el : document;	
				var i = 0;
				var timer = setInterval(function() {
					if(i<100) {
						i++;
						el.innerHTML = i;
					} else {
						clearInterval(timer);
					}
				},time)
			}
		}


效果图:



如果想要调整进度时间,需要修改css样式中animation的时间和js中的时间



PS:css未做前缀处理,所有测试都在最新谷歌浏览器下进行

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值