Search code examples
jqueryjquery-uieventsdraggablejquery-ui-draggable

With Jquery ui's draggable, how do you change the revert on stop?


I was wondering how you changed the "revert" property of something being dragged in Jquery ui from the stop event.

    $('.things').draggable({ 
        revert: "true",
        stop: function(event, ui){
                        //if something then set revert to false
        }
    });

I've tried a few things but I can't seem to get it to work.

Cheers.


Solution

  • The stop event occurs too late for changes to the revert option to affect the current drag operation. The draggable will still revert, even if it won't do so anymore in the next drags.

    You might want to bind to the drag event instead:

    $('.things').draggable({ 
        revert: true,
        drag: function(event, ui) {
            if (/* something */) {
                $(this).draggable("option", "revert", false);
            }
        }
    });