问题
As it seems like I have found a bug in jquery:
jquery draggable throws error when 'mouseup' is triggered
Can I get some advice on how to implement the following functionality without using the trigger?
I want to be able to stop an element to be dragged when a condition has been reached, I have been trying lot's of possibilities but none works automatically, even though the event is fired when condition is true it only takes effect when you "mouseup" the dragger.
I'm really trapped on this, any help will be very appreciated.
P.D: I have already posted the bug in jquery.ui
回答1:
The following piece of code worked for me well. There isn't any method that cancels only one "dragging", but you can set the position of the object using ui.position
$('#draggablediv').draggable({
drag: function (event, ui) {
if (your_condition) { // for example: ui.position.left < 100
ui.position.left = ui.position.left_old
ui.position.top = ui.position.top_old
}
ui.position.left_old = ui.position.left
ui.position.top_old = ui.position.top
}
})
来源:https://stackoverflow.com/questions/2927020/alternatives-to-triggermouseup-to-stop-dragging-programmatically