删除之后调用jQuery dravertable的revert

时间:2014-06-19 11:07:53

标签: javascript jquery jquery-ui

我正在使用jQuery UI创建一个带拖放功能的简单可拖动div。 将div放在几个目标中的一个之后,我调用一个函数来查看这个目标是否正确。我需要这个函数,因为每次删除div时条件都不同。

我的问题:即使在评估“掉落”功能后,如何调用“恢复”效果? 只是调用“.revert()”不会做任何事情。

// 
// a draggable block
//
$(".textblock").draggable({
    cursor: 'move',
    stack: ".textblock",
    stop: function(e,ui) {
        //
    },
    // reverts when not dropped in the right div
    revert: "invalid"
});

//
// evaluate the drop target after div is dropped
//
$(".icon").droppable({
    hoverClass: "hovering",
    tolerance: "fit",

    drop: function(e,ui) {
        // if some condition is false, revert the div to original position
        // in the same way as when the div was dragged outside the droppable?
        // revert() doesnt work
        if(someCondition == false) ui.draggable.revert();
    }
});

1 个答案:

答案 0 :(得分:0)

您似乎想使用可放置接受 JQuery UI功能。

它允许你做这样的事情:

$('.droppable').droppable({
    accept: ".draggable"
});

使用droppable类,您可以定义哪些元素无效。