【发布时间】:2011-12-25 18:41:30
【问题描述】:
我有一个名为“面板”的 div,它本身包含另一个 div。当用户在“面板”上单击(并按住鼠标)并向左或向右拖动时,将向左或向右拖动内部 div。当用户释放点击时,内部 div 的拖动停止。在大多数情况下,这没有问题。
我遇到的问题是当用户拖动并且鼠标离开“面板”时,拖动继续。在这种情况下,当用户释放鼠标按钮时,拖动仍会继续,因为未达到 mouseup 事件可能是因为 mouseup 事件发生在“面板”之外。
这是我正在使用的代码:
$(document).ready(function() {
$('#panel').bind("mousedown", function (e) {
StartDrag(); // Code to drag inner panel goes here
}).bind("mouseup", function (e) {
StopDrag(); // Code to stop drag goes here
}).bind("mouseout", function (e) {
$(this).unbind("mousedown"); // This line doesn't help
StopDrag();
});
});
如果我将 StopDrag() 函数绑定到整个文档,那么它会干扰 StartDrag()。
如何确保我可以在 mouseup 时触发我的 StopDrag() 函数,而不管它发生在哪里?
【问题讨论】:
标签: jquery