js缓速运动
2015-10-16 11:20
549 查看
<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>
相关文章推荐
- JSP结合js实现img中src更新请求的方法
- Servlet跳转jsp并将list传给jsp
- JS堆栈与拷贝
- 接口API测试和返回值JSON解析的插件
- JS模拟Dialog弹出浮动框效果代码
- web中使用到的一些关于坐标相关知识
- 正则表达式详细介绍(下)
- JavaScript 跨域(CORS)
- js对象
- JS实现仿腾讯微博无刷新删除微博效果代码
- 解决JS请求服务器gbk文件乱码的问题
- 正则表达式详细介绍(上)
- jsonp使用
- HighchartsJS创建点状带标识的图表实例
- DynamicJson
- jsp中的简单文件上传
- JSF框架认识
- js中(function(){…})()立即执行函数写法理解
- 百度JSP版坐标转换 限定不大于10个每次的处理办法
- js实现观察者模式