运动基础 学习笔记
2015-06-04 11:50
225 查看
http://bbs.zhinengshe.com/thread-1194-1-1.html
运行效果:[http://runjs.cn/code/riwpoev9]
运行效果:[http://runjs.cn/code/aoznxlv9] ;
存在问题:物体运动卡顿 ;
运行效果:[http://runjs.cn/code/x4akoomk]
(2)解决方案:修改oDiv.style.left = oDiv.offsetLeft + 10 + "px" 中的 10 ;
运行效果:[http://runjs.cn/code/x8mtz0vr]
View Code
解决方案:添加else从句;
运行效果:[http://runjs.cn/code/ewbl7uzy]
运行效果:[http://runjs.cn/code/i89ybgtc]
运行效果:[here]
运行效果:[http://runjs.cn/code/riwpoev9]
问题1:不会在特定的位置停止 ~
解决方案:添加if判断条件,达到特定位置时关闭定时器 ;运行效果:[http://runjs.cn/code/aoznxlv9] ;
问题2:如何改变物体运动速度 ?
(1)不可行方案:修改定时器间隔为300ms ;存在问题:物体运动卡顿 ;
运行效果:[http://runjs.cn/code/x4akoomk]
(2)解决方案:修改oDiv.style.left = oDiv.offsetLeft + 10 + "px" 中的 10 ;
运行效果:[http://runjs.cn/code/x8mtz0vr]
问题3:物体运动到终点后,点击按钮,物体仍然会运动 ~
原因:这里虽然在offsetLeft>=300时clearInterval,但是setInterval()仍然会被执行一次;setInterval(function () { if (oDiv.offsetLeft >= 300) { clearInterval(timer); } oDiv.style.left = oDiv.offsetLeft + speed + "px"; }, 30);
View Code
解决方案:添加else从句;
运行效果:[http://runjs.cn/code/ewbl7uzy]
问题4:物体运动过程中,连续点击按钮会叠加定时器 ~
解决方案:在打开定时器前关闭之前的定时器,保证每次只有一个定时器在工作 ;运行效果:[http://runjs.cn/code/i89ybgtc]
问题5:匀速运动物体来回抖动
解决方案:当abs(iTarget-oDiv.offsetLeft)<speed时,关闭定时器,并让oDiv.style.left=iTarget+"px";运行效果:[here]
相关文章推荐
- python re-raise exception
- Eclipsez中打不开c++文件,显示Editor could not be initialized.
- Unicode的定义以及Windows下各个相关名称叫法间的关系
- ODROID-X2 SD card install Arch linux
- iOS学习笔记——iOS国际化
- linux: 获取系统资源(getconf(1), sysconf(3))
- Infragistics用户界面组件宣布推出infragistics Ultimate更新15.1版本。
- 网络定位服务NetworkLocationProvider
- 怎样在多线程中使用JNI?
- win8和win8.1动态绑定数据到ListView
- SUDO的有关知识总结
- android studio 如何导入eclipse工程
- Ubuntu 14.04安装语言包后无法选择汉语问题解决
- Android底层开发(二)之JNI层 第三步
- LIB和DLL的区别与使用
- iOS学习笔记——获取手机信息(UIDevice、NSBundle、NSLocale)
- ArcGIS Engine中正确释放打开资源<转>
- [转]五种常见的 PHP 设计模式
- mac eclipse 修改SDK路径
- 添加产品唯一性限制以后,复制按钮不能使用