Reputation: 15186
I have a jquery ui as follows:
$('.draggable').draggable({
drag: function(event, ui){
if(this.offsetTop > 0 || this.offsetLeft > 0) return false;
}
})
Basically I want it so that every time user drags, i want to continuously test for a condition to be true (in this case, i want the top and left side of draggable to stick to the side of parent).
I thought the above code will just cancel that particular drag event, but it seems to have stopped dragging altogether. Any idea how to just cancel a drag event when a condition is satisfied?
Thanks a lot!
Jason
Upvotes: 1
Views: 4121
Reputation: 18078
To keep the draggable alive, don't return false. From what you say, you probably need to do something to limit the position of the dragged (ui) element.
Here's a fiddle I put together in response to another SE question.
Upvotes: 2