jquery droppable accept

后端 未结 8 2127
轻奢々
轻奢々 2020-12-13 07:02

Can anyone tell me how I can write a function in accept condition and then how does it finds out that what to accept and what not to accept. For example, I want to accept

相关标签:
8条回答
  • 2020-12-13 07:48

    Instead of using a class as accept, you can just use a function like and return true if it matches your criteria

    $('#mydroppable').droppable(
    {
        accept: function() { return true; },
        drop: function () { alert("Dropped!"); }
    });
    
    0 讨论(0)
  • 2020-12-13 07:48

    This is my solution:

    var foo = true;
    
    $( ".draggable" ).draggable({ 
                            revert: function(){if(foo == true){return true;}else{foo = true;}},
                             });
    
        $("#droppable").droppable({
            activeClass: "ui-state-hover",
            hoverClass: "ui-state-active",
            drop: function( event, ui ) {
                if($this == $that){
                    foo = true;
                    alert("this will revert the draggable back to original position");
                }else{
                    foo = false;
                    alert("this will NOT revert the draggable back to original position");
                }
            }
        });
    
    0 讨论(0)
提交回复
热议问题