div动画展开

div动画展开

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>title</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    div {
      width: 200px;
      height: 150px;
      background-color: red;
      border-radius: 100px;
    }
  </style>
</head>
<body>
<input type="button" value="展开" id="btn"/>
<div id="div"></div>

<script>
  document.getElementById("btn").onclick = function () {
    var width = 200;
    var timeId = setInterval(function () {
      width+=10;
      if(width==800){
        clearInterval(timeId);
      }
      document.getElementById("div").style.width=width+"px";
    }, 20);
  };
</script>

</body>
</html>
发布了116 篇原创文章 · 获赞 4 · 访问量 1760

猜你喜欢

转载自blog.csdn.net/qq_43618136/article/details/104293942