javascript运动功能-分享到
2015-10-08 16:57
253 查看
<script> //窗体载入,为div控件绑定事件 window.onload = function () { var div1 = document.getElementById('div1'); //mouseover div1.onmouseover = function () { startMove(0); } //mouseout div1.onmouseout = function () { startMove(-100); } } //定义定时器 var timer = null; //淡入和淡出 function startMove(targetPoint) { clearInterval(timer); var div1 = document.getElementById('div1'); timer = setInterval(function () { var ispeed = 0; if (div1.offsetLeft < targetPoint) { ispeed = 10; } else { ispeed = -10; } //控件位置 if (div1.offsetLeft == targetPoint) { clearInterval(timer); } else { div1.style.left = div1.offsetLeft + ispeed + "px"; } },30); } </script>
相关文章推荐
- js判断鼠标位置是否在某个div中
- Ajax通过jsonp实现跨域访问,访问成功但走error不走success
- js-对象prototype属性剖析
- js复制剪切应该很简单
- javascript小知识点
- javascript弹窗和对话框
- 151008:javascript不明白的地方
- Javascript学习笔记
- JavaScript中函数传入参数与外部变量绑定
- 高性能JavaScript:脚本的无阻塞加载策略
- javascript设计模式之Decorator(装饰者)模式
- 转: JS自定义事件的定义和触发(createEvent, dispatchEvent)
- js 第一节
- (五)我的JavaScript系列:JavaScript的糟粕
- JavaScript 面向对象详解
- javascript规范
- extjs初学者教程
- Javascript DOM
- JS获取浏览器型号
- C#中js无效,不弹出提示语句,与ScriptManager冲突导致