首页 > Web开发 > 详细

js--缓冲运动

时间:2015-11-30 11:32:48      阅读:244      评论:0      收藏:0      [点我收藏+]
技术分享
<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="content-type" charset="utf-8" />
    <meta http-equiv="content-type" content="text/html" />
    <title>demo</title>
</head>
<body>
<div id="odiv" style="position:absolute;width:200px;height:200px;background:red;left:0;"></div>
<div id="odiv1" style="position:absolute;width:200px;height:200px;background:red;left:0;top:250px;"></div>

<script type="text/javascript">
    var odiv=document.getElementById(odiv);
    var odiv1=document.getElementById(odiv1);
    odiv.onclick=function(){move(odiv,500);}
    odiv1.onclick=function(){move(odiv1,500);}
    function move(obj,target){
        clearInterval(dt);
        var dt=setInterval(function(){
            var ol=parseInt(obj.style.left);
            if(ol==target){
                clearInterval(dt);
            }else{
                var speed=(target-ol)/8;
                speed>0?speed=Math.ceil(speed):speed=Math.floor(speed);
                obj.style.left=ol+speed+"px";
            }
        },30);
    }

</script>
</body>
</html>
View Code

 

js--缓冲运动

原文:http://www.cnblogs.com/lanyueff/p/5006631.html

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