码迷,mamicode.com
首页 > 其他好文 > 详细

将一个200*200的盒子以200ms/10px的速到增到到400px之后再以同样的方式缩放到原来的位置

时间:2017-05-16 20:52:41      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:function   var   span   --   练习   charset   tle   速度   练习题   

 

<!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <title>练习题</title>
    </head>
    <style type="text/css">
        .box {
            height: 200px;
            width: 200px;
            background: red;
        }
    </style>

    <body>
        <!--让一个200px的盒子以每秒10px的速度增大到400,再返回到200px-->
        <div class="box">这是200*200的盒子</div>
        <script type="text/javascript">
            var box = document.getElementsByClassName(box)[0];
            var speed = 0;

            function move1() {
                speed += 10;
                box.style.width = 200 + speed + px;
                box.style.height = 200 + speed + px;
                if(speed >= 200) {
                    clearInterval(t1);

                    function move2() {
                        speed -= 10;
                        box.style.width = 200 + speed + px;
                        box.style.height = 200 + speed + px;
                        if(speed <= 0) {
                            clearInterval(t2);
                        }
                    };
                    var t2 = setInterval(move2, 200);
                };
            };
            var t1 = setInterval(move1, 200);
        </script>
    </body>

</html>

 

将一个200*200的盒子以200ms/10px的速到增到到400px之后再以同样的方式缩放到原来的位置

标签:function   var   span   --   练习   charset   tle   速度   练习题   

原文地址:http://www.cnblogs.com/tanxiang6690/p/6863466.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!