首页 > 其他 > 详细

缓冲运动

时间:2015-05-08 09:23:16      阅读:121      评论:0      收藏:0      [点我收藏+]
 1 var timer = null;
 2 
 3     function startMove(iTarget){
 4         var oDiv = document.getElementById(div1);
 5         //h缓冲运动的核心是距离与速度成正比,同时一定需要用到函数取整
 6         clearInterval(timer);
 7         timer = setInterval(function(){
 8             //速度与距离成正比,达到缓冲运动的条件
 9             var speed = (iTarget-oDiv.offsetLeft)/10;
10             //距离为正,是向上取整,距离向下 是向下取整
11             speed =speed>0?Math.ceil(speed):Math.floor(speed);
12 
13             if (oDiv.offsetLeft>=iTarget) {//是否到达终点
14                 clearInterval(timer);//到达终点
15             } else{
16                 oDiv.style.left = oDiv.offsetLeft+speed+px;
17                 //到达之前
18             };
19         },30);
20 
21     }

 

缓冲运动

原文:http://www.cnblogs.com/xs-yqz/p/4486736.html

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