js缓冲运动和匀速运动
来源:互联网 发布:linux ll命令输出内容 编辑:程序博客网 时间:2024/05/18 00:31
1.缓冲运动
<span style="font-size:12px;"><!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title>js缓冲运动</title> <style> #div1{ height: 100px; width: 100px; background-color: red; position: absolute; left: 0px;/*700px*/ top: 100px; } #span1{ position: absolute; left: 500px; top: 0; height: 500px; width: 1px; background-color: #000; } </style> <script> window.onload=function(){ var oInput=document.getElementById("input1"); var oDiv=document.getElementById("div1"); var timer=null; function startMove(iTarget){ clearInterval(timer); timer=setInterval(function(){ var iSpeed=(iTarget-oDiv.offsetLeft)/8;//缓冲运动速度 if(iSpeed>0){ iSpeed=Math.ceil(iSpeed); }else{ iSpeed=Math.floor(iSpeed); } if(oDiv.offsetLeft==500){ clearInterval(timer); }else{ oDiv.style.left=oDiv.offsetLeft+iSpeed+'px'; } },30) }; oInput.onclick=function(){ startMove(500); } } </script></head><body><input type="button" id="input1" value="开始运动" /><div id="div1"></div><span id="span1"></span></body></html></span>
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title>js匀速运动</title> <style> #div1{ height: 100px; width: 100px; background-color: red; position: absolute; left: 0px;/*700px*/ top: 100px; } #span1{ position: absolute; left: 500px; top: 0; height: 500px; width: 1px; background-color: #000; } </style> <script> window.onload=function(){ var oInput=document.getElementById("input1"); var oDiv=document.getElementById("div1"); var timer=null; function startMove(iTarget){ clearInterval(timer); timer=setInterval(function(){ var iSpeed=iTarget>oDiv.offsetLeft>0?7:-7;// if(iTarget>oDiv.offsetLeft){// iSpeed=7// }else{// iSpeed=-7;// } if(Math.abs(oDiv.offsetLeft-iTarget)<=7){ oDiv.style.left=iTarget+'px'; clearInterval(timer); }else{ oDiv.style.left=oDiv.offsetLeft+iSpeed+'px'; } },30) }; oInput.onclick=function(){ startMove(500); } } </script></head><body><input type="button" id="input1" value="开始运动" /><div id="div1"></div><span id="span1"></span></body></html>
0 0
- js缓冲运动和匀速运动
- js运动技术--匀速运动
- js动画之匀速运动、缓冲运动、弹性运动、碰撞运动、属性变化动画
- [js运动动画]运动之匀速运动框架
- js运动-运动缓冲
- 原生Js完美运动框架(缓冲运动和弹性运动)
- js 运动框架(一)匀速运动
- Js运动动画系列1--匀速运动
- Javascript运动概念1——缓冲运动、匀速运动、运动框架
- js运动(2)----缓冲运动
- js运动技术--缓冲运动
- JS的缓冲运动
- JS缓冲运动
- js缓冲运动框架
- JS缓冲运动
- js缓冲运动
- js缓冲运动
- 关于js缓冲运动
- 使用ide编辑pomelo代码
- jdk7之fork-join
- Tomcat 监控
- 自定义View(二、方法分析)
- 网页源码查看器
- js缓冲运动和匀速运动
- 江苏电信用户将体验iPhone6s的极速4G+网络
- 多实例tomcat管理脚本
- 【Developer Log】MySQL远程连接时间长的原因和解决方式
- SD卡驱动分析
- GCD 之线程死锁
- mac版eclipse修改主题
- Android shap selector animation 与 Toast退出问题
- 节日-CCF测试往届题(80分)仍在debug,求指导