JavaScript 点击按钮div变宽

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
        div {
            width: 100px;
            height: 50px;
            background-color: forestgreen;
        }
    </style>
</head>
<body>
<div id="dv"></div>
<input type="button" id="bt" value="变宽"/>
<script src="common.js"></script>
<script>
    my$("bt").onclick = function () {
        var width = 100;
        var timeId = setInterval(function () {
            width+=10;
            my$("dv").style.width = width+"px";
            if(width == 900) {
                clearInterval(timeId);
            }
        }, 10)
    };
</script>
</body>
</html>

 

posted @ 2018-08-01 17:13  {颜逸}  阅读(1253)  评论(0编辑  收藏  举报