js原生进度条

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>进度条</title>

	<style text="text/css">
    #frame .border{
      width: 300px;
    	margin:10px 30px;
    	border:2px solid black;
    	height: 30px;
    	background-image: -moz-linear-gradient(top,#b0b0b0,#f8f8f8);
    	background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0,#b0b0b0),color-stop(1,#f8f8f8));
    	filter: progid:DXImageTransfrom.Microsoft.gradient(startColorstr='#b0b0b0',endColorstr='#f8f8f8',GradientType='0');

    	overflow: hidden;
    	position: relative;

      border: 2px solid black;
      border-bottom-width:4px;
      border-top-width: 3px; 
      border-radius:50px;
    }
    #frame .border #bar{
    	width: 1%;
    	height: 100%;
    	background-image: -moz-linear-gradient(top,#b0b0b0,#f8f8f8);
    	background-image: -webkit-gradient(linear,left top,left bottom,color-stop(0,#8efb3c),color-stop(1,#7ac478));
    	filter: progid:DXImageTransfrom.Microsoft.gradient(startColorstr='#8efb3c',endColorstr='#7ac478',GradientType='0');

    /*	-webkit-border-top-right-radius:10px;
    	border-top-right-radius:10px;

    	-webkit-border-bottom-right-radius:10px;
    	border-bottom-right-radius:10px;*/

    	-webkit-transition:all 0.1s ease-in-out 0s;
    	transition:all 0.1s ease-in-out 0s;
    }
    #frame .border #persentage{
    	position: absolute;
    	left:0;
    	top:0;
    	width: 100%;
    	text-align: center;
    	padding:5px;
    	color: red;
    	font-weight: bold;
    }
	</style>
</head>
<body>
  <div id="frame">
		<div class="border">
			<div id="bar">
				
			</div>
			<div id="persentage">
				0%
			</div>
		</div>              
  </div>
  <script type="text/javascript">
    function Update () {
      var frm = document.getElementById("frame")
      var list = document.getElementsByTagName("div")
      var bar = document.getElementById('bar')
      var persentage = document.getElementById('persentage')
      console.log(bar.style.width, '1')
      if (bar.style.width === '') {
        bar.style.width = '1%' // 设置宽度
      } else {
        console.log(parseFloat(bar.style.width))
        bar.style.width = parseFloat(bar.style.width) + 1 + "%";
      }
      persentage.textContent = parseFloat(bar.style.width) + "%"
      if (bar.style.width !== '100%') {
        window.setTimeout('Update()', 100) // 设置超时
      }
    }
    Update()
  </script>
</body>
</html>

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值