首页 > Web开发 > 详细

js缓速运动

时间:2015-10-16 13:07:53      阅读:283      评论:0      收藏:0      [点我收藏+]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<style>
*{margin:0;padding:0;}
#w{width:200px;height:200px;background:#ccc;overflow:hidden;position:relative;left:0px;}
#w1{width:400px;height:200px;}
</style>
<script>
window.onload=function(){
    var oDiv=document.getElementById("w");
    var oDiv1=document.getElementById("w1");
    var oIput=document.getElementById("btn");
    var oTxt=document.getElementById("txt");
    var speed=0;
    var timer=null;//timer=setInterval(sMove,1000);
    
    /*减速运动*/
    
    function mMove(target){
        speed=(target-oDiv.offsetLeft)/8;
        speed = speed>0?Math.ceil(speed):Math.floor(speed);
        if(oDiv.offsetLeft==target){

            clearInterval(timer);
            console.log("计时器停止"+speed);
            
        }else{
            oDiv.style.left=oDiv.offsetLeft+speed+"px";
            console.log("speed="+speed);
            console.log("oDiv.offsetLeft="+oDiv.offsetLeft);
        }
    }
    oIput.onclick=function(){
        timer=setInterval(function(){mMove(oTxt.value)},100);
    };

};
</script>
<body>
<input type="button" value="button" id="btn" />
<input  type="text" id="txt" />
<div id="w">
    <div id="w1"></div>
</div>
</body>
</html>

 

js缓速运动

原文:http://www.cnblogs.com/dream-w/p/4884770.html

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