码迷,mamicode.com
首页 > 编程语言 > 详细

JavaScript之动画缩放

时间:2017-10-28 17:49:33      阅读:300      评论:0      收藏:0      [点我收藏+]

标签:art   oct   cli   缩放   java   width   rip   var   offset   

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <style type="text/css">
        .div{
            width: 200px;
            height: 200px;
            background-color: lightgreen;
        }
    </style>
</head>
<body>
<div class="div"></div>
<script type="text/javascript">
    window.onload=function(){
        var div=document.getElementsByClassName(div)[0];
        var timer=null;
        function larger(obj,goal,speed){
            var offsetwidth=obj.offsetWidth;
            var offsetheight=obj.offsetHeight;
            if(offsetwidth<goal&&offsetheight<goal){
                obj.style.height=(offsetheight+speed)+px;
                obj.style.width=(offsetwidth+speed)+px;
                clearTimeout(timer);
                timer=setTimeout(function(){
                    larger(obj, goal, speed);
                },50);
            }
            else{
                clearTimeout(timer);
            }
        }
        div.onclick=function(){
            larger(this, 400, 10);
        }
    }
</script>
</body>
</html>

 

JavaScript之动画缩放

标签:art   oct   cli   缩放   java   width   rip   var   offset   

原文地址:http://www.cnblogs.com/chenyongyang/p/7747169.html

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