js拖拽事件及bug修复
2016-10-13 00:01
197 查看
author:卢~耐
拖拽原理:
三个事件:onmousedown,onmouseover,onmouseup
在firefox下,对象的拖拽bug:阻止默认事件
拖拽原理:
三个事件:onmousedown,onmouseover,onmouseup
在firefox下,对象的拖拽bug:阻止默认事件
<!DOCTYPE html> <head> <meta charset="utf-8" /> <title>无标题文档</title> <style> #div1 {width:60px; height:60px; background:red; position:absolute;} </style> <script> window.onload=function (){ var oDiv=document.getElementById('div1'); var disX=0; //鼠标点的水平位置 var disY=0; oDiv.onmousedown=function(ev){ var oEvent=ev||event; disX=oEvent.clientX-oDiv.offsetLeft; disY=oEvent.clientY-oDiv.offsetTop; document.onmousemove=function (ev){ //兼容性处理 var oEvent=ev||event; var left=oEvent.clientX-disX; var top=oEvent.clientY-disY; <span style="font-family:微软雅黑;"> </span>//阻止物体被拖出<span style="font-family:微软雅黑;">可视区</span> if(left<0){ //left left=0; //right }else if(left>document.documentElement.clientWidth-oDiv.offsetWidth){ left=document.documentElement.clientWidth-oDiv.offsetWidth; } if(top<0){ top=0; }else if(top>document.documentElement.clientHeight-oDiv.offsetHeight){ top=document.documentElement.clientHeight-oDiv.offsetHeight; } oDiv.style.left=left+'px'; oDiv.style.top=top+'px'; }; document.onmouseup=function (){ document.onmousemove=null; document.onmouseup=null; }; //<span style="color:#FF6600;">return false</span>; //firefox }; }; </script> </head> <body> <span style="font-family:微软雅黑;"> </span><div id="div1"></div> </body> </html>
相关文章推荐
- JS:简单的拖拽事件和bug修复
- js-鼠标拖拽窗口bug修复
- TreeView单击事件的BUG修复及深入探讨返回事件
- Flex List 选项变灰,信息过长有提示,修复dragComplete事件不准的BUG
- 价值100W的经验分享: 基于JSPatch的iOS应用线上Bug的即时修复方案,附源码.
- JS 事件基础 拖拽
- JSPatch-iOS热补丁方式快速修复bug
- C#WindowsForm拖拽事件一例bug分析
- iOS 通过 JSPatch 实时修复线上 bug!
- JS事件中级 --- 拖拽
- jquery-perfect-scoller.js的一个bug修复
- JS 事件基础 边框拖拽
- IE9的一个BUG:propertychange和input事件在拖拽 / 剪切 / 删除时无法触发
- dede 修复更新联动缓存 不更新联动js的bug
- iOS 动态更新 修复bug jspatch wax总结。
- [转][ASP.NET]TreeView单击事件地BUG修复及进一步探讨返回事件
- js ie input onchange事件兼容BUG
- 一个页面使用两次timepicker.js引起的Maximum call stack size exceeded问题解决办法及bug修复
- 基于JSPatch的iOS应用线上Bug的即时修复方案,附源码.
- iOS动态修复App线上Bug 之 JSPatch