js 进度条03

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .box{
            width: 300px;
            height: 30px;
            margin: 0 auto;
            position: relative;
            border: 2px solid red;
        }
        .nav{
              height: 100%;
              background:blue;
              position: absolute;
              left: 0;
              top: 0;
           
        }

    
    </style>
</head>
<body>
    <div class="box">
        <div class="nav">

        </div>

    </div>
</body>
<script>
 var nav=document.querySelector(".nav");
 var t;
 var speed=1;
//  var w= nav.offsetWidth;
t= setInterval(function(){
      if(nav.offsetWidth<=300){
           nav.style. width=(nav.offsetWidth)+speed+"px";
      } 
},30)



</script>
</html>

效果图

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_45555960/article/details/102514079