我的页面中有一个可拖动的 div。在第一次拖动时它完美地工作。在第二次拖动时它开始工作,但随后 div 似乎被“捕获”,就好像它是图像一样 - 拖动停止,出现 div 的“副本”并且未注册 mouseup 事件。如果我还不够清楚,则与这些人的问题相同:http://www.webdeveloper.com/forum/showthread.php?t=227602
知道是什么原因造成的以及如何克服吗?
谢谢
编辑:好的,我找到了答案,感谢 this问题。为了让 future 的访问者不再点击,在您的 dragStart
函数中确保您以 event.preventDefault()
结尾:
// bind dragStart handler to appropriate element:
<script type="text/javascript">
$("#handle").bind("mousedown", function(e) { dragStart(e) });
</script>
function dragStart(event) {
// bind mousemove and mouseup handlers to $(document),
// get ininitial positions etc
...
// then do this:
event.preventDefault();
}
嘿嘿,一切都很好。
最佳答案
@RichardH:另外,请考虑 CSS 中的以下内容:
#handle {
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-o-user-select: none;
user-select: none;
}
这将禁止在拖动时意外选择元素。
关于javascript - 可拖动的 div : behaves like an image on second drag,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8079198/