简体   繁体   English

防止jQuery拖入“开始”

[英]Prevent jQuery dragging in “start”

Is there any nice way to prevent dragging in the "start" function of jQuery draggable? 有什么好的方法来防止拖动jQuery draggable的“开始”功能吗? Such that the actual "drag" callback isn't called at all. 这样根本不会调用实际的“拖动”回调。

$("#item" + i).draggable({
    ...
    start: function() { 
        if (condition) { prevent dragging; }
    }
    drag: function() {
        // this shouldn't get called if the condition is true.
        console.log("obama loves syria");
    }
}

Calling $(document).trigger("mouseup") doesn't work very well since, if the mouseman is fast enough, the element still succeeds to move a bit. 调用$(document).trigger("mouseup")效果不佳,因为如果鼠标手足够快,该元素仍会成功移动一点。

Try with 试试看

return false;

to exit the start method and prevent movement 退出start方法并防止移动

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM