开发者

How to get whether revert has happened?

I am using draggable a开发者_StackOverflow社区nd droppable features of jquery-ui. I need to identify whether revert has happened.

Is it possible to trap whether "revert" has happened or not?


Feels a bit hacky, but a possible solution would be the following:

    $("#draggable").draggable({ revert: function(){if($('#droppable').hasClass('logRevert') == true){
            $('#droppable').removeClass('logRevert'); return false; 
    } 
else{
/*Your Code here*/
return true;
} 
});

revert accepts a function, so we only return true, if the draggable is not accepted, for whatever reason.

Now to make this work, we have to add our .logRevert-class when an acceptable draggable is above the droppable. After it drops and doesn't get reverted, it removes the helper-class .logRevert. You can now always add code to the return

$("#droppable").droppable({
    accept: '#draggable',
    over: function(event, ui){$(this).addClass('logRevert');},
    drop: function(event, ui) {
        $(this).addClass('ui-state-highlight').find('p').html('Dropped!');
    }
});

Derived from Nick Craver's answer on: jQuery draggable revert based on condition

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜