标签:
http://bbs.zhinengshe.com/thread-1194-1-1.html
运行效果:[http://runjs.cn/code/riwpoev9]
解决方案:添加if判断条件,达到特定位置时关闭定时器 ;
运行效果:[http://runjs.cn/code/aoznxlv9] ;
(1)不可行方案:修改定时器间隔为300ms ;
存在问题:物体运动卡顿 ;
运行效果:[http://runjs.cn/code/x4akoomk]
(2)解决方案:修改oDiv.style.left = oDiv.offsetLeft + 10 + "px" 中的 10 ;
运行效果:[http://runjs.cn/code/x8mtz0vr]
原因:这里虽然在offsetLeft>=300时clearInterval,但是setInterval()仍然会被执行一次;
1 setInterval(function () { 2 if (oDiv.offsetLeft >= 300) { 3 clearInterval(timer); 4 } 5 oDiv.style.left = oDiv.offsetLeft + speed + "px"; 6 }, 30);
解决方案:添加else从句;
运行效果:[http://runjs.cn/code/ewbl7uzy]
解决方案:在打开定时器前关闭之前的定时器,保证每次只有一个定时器在工作 ;
运行效果:[http://runjs.cn/code/i89ybgtc]
标签:
原文地址:http://www.cnblogs.com/linxd/p/4551394.html