Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 494
MintDeparture Avatar asked Aug 14 '11 11:08

MintDeparture


1 Answers

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);
        }
    }
});
like image 193
Frédéric Hamidi Avatar answered Oct 19 '22 22:10

Frédéric Hamidi