js练习 进度条

点击开始,读取进度条,数字显示读取百分比

<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style type="text/css">
    *{ margin:0 auto; padding:0;}
    #wai{ width:320px; height:30px; margin-top:100px;}
    #btn{ width:50px; height:30px; margin-right:20px; background-color:#00F; text-align:center; line-height:30px; color:#fff; float:left;}
    #kuang{ width:200px; height:28px; border:1px solid blue; float:left; }
    #btn:hover{ cursor:pointer;}
    #jindu{ height:28px; background-color:blue; margin-left:0;}
    #shu{ width:30px; height:30px; text-align:center; line-height:30px; float:left;}
</style>
</head>

<body>
    <div id="wai">
        <div id="btn">开始</div>
        <div id="kuang">
            <div id="jindu" style=" width:0%;"></div>
        </div>
        <div id="shu">0</div>
    </div>

</body>
</html>
<script type="text/javascript">
    var btn = document.getElementById("btn");
    var jindu = document.getElementById("jindu");
    var shu = document.getElementById("shu");
    var ids;
    /*
        点击开始读取进度条
    */
    btn.onclick = function()
    {
        ids = window.setInterval("bian()",20)
    }
    /*
        进度条在达到100%前增长1%,数字显示增加1
    */
    function bian()
    {
        var jd = parseInt(jindu.style.width);
        if(jd<100)    
        {
            jd++;
        }
        else
        {
            window.clearInterval(ids);//达到100%清除间隔
        }    
        jindu.style.width = jd+"%";
        shu.innerText = jd;
    }

</script>

效果 

 

转载于:https://www.cnblogs.com/zxbs12345/p/8004631.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值