只使用jQuery ui droppable在某个接受上运行和运行

时间:2013-12-11 11:09:41

标签: javascript jquery jquery-ui jquery-ui-draggable jquery-ui-droppable

   $(function() {
    $( "#d1o1" ).droppable({

        accept: "#s1o2, #s1o1, #s1o3, #s1o4, #s1o5, #s1o6",

        over: function (){
            $( "#d1o1" ).droppable( "option", "d1o1Check", "1" );
        },
        out: function () {
            $( "#d1o1" ).droppable( "option", "d1o1Check", "0" );
        },

    })
 });

目前,dropable#d1o1接受所有可拖动的因为我希望它们在掉落时保持不变。但是,我只希望在#s102被删除时运行'over'和'out'函数。怎么可以接受所有可拖动的东西,但只有在某个拖拽被剔除时才会跑来跑去?

1 个答案:

答案 0 :(得分:0)

当可拖动移动到droppable时,您可以检查它是否符合 over out 功能的条件:

$(function() {
$( "#d101" ).droppable({

    accept: "#s102, #s101, #s103, #s104, #s105, #s106",

    over: function (event, ui){ // Don't forget to add these parameters for the function
        if($(ui.helper).is('#s102')) // <-- Add this line
            $( "#d101" ).droppable( "option", "d1o1Check", "1" );
    },
    out: function (event, ui) { // Don't forget to add these parameters for the function
        if($(ui.helper).is('#s102')) // <-- Add this line
            $( "#d101" ).droppable( "option", "d1o1Check", "0" );
    },

});
$('.drag').draggable();
});

这是有效的jsFiddle