开发者

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

I was wondering how you changed the "reve开发者_JAVA技巧rt" 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.


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);
        }
    }
});


I realize this has been a while since this question was asked, but in JQuery UI 1.10 and above draggable now supports a function as a value for revert. If the value returns true then the position is reverted otherwise it does not.

$('.things').draggable({ 
    revert: function() {
        if(condition_is_met()) {
             return false; // Don't revert
        } else {
             return true;
        }
    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜