html与js生成的滚动条

2017-05-24  本文已影响0人  无敌万小奔
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>Document</title>
    <style>
        #d1 {
            width: 800px;
            height: 40px;
            border: 2px solid black;
        }
        #d2 {
            width: 0;
            height: 40px;
            background: blue;
        }
    </style>
</head>
<body>
    <h1>滚动条</h1>
    <hr>
    <div id="d1">
        <div id="d2"></div>
    </div>
    <br>
    <button id="btn">开始</button>
</body>
<script>
    var oDiv2=document.getElementById('d2');
    var oBtn=document.getElementById('btn');
    var i=document.getElementById('d2').style.width;
    oBtn.onclick=function(){
    var timer=setInterval(run,10);
    function run(){
        if(i==800){
            return;
        }
        i++;
        oDiv2.style.width=i+'px';
    }
}
</script>
</html>
上一篇下一篇

猜你喜欢

热点阅读