首页 > 其他 > 详细

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

时间:2017-05-16 20:30:17      阅读:331      评论:0      收藏:0      [点我收藏+]

 

<!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之后再以同样的方式缩放到原来的位置

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!