jQuery UI remove element when dropped into a div using .droppable

前端 未结 3 1242
执念已碎
执念已碎 2021-01-01 03:29

I\'m trying to figure out the logic of how to do this.

I have many images with only a CSS class name, they are created dynamically.

These images are draggabl

3条回答
  •  迷失自我
    2021-01-01 03:50

    You can find the item being dragged by using .draggable property of the ui element being passed to the callback function of over, as specied in the docs. Like this:

    $(function() {
        $(".stack").draggable();
    
        $('#trash').droppable({
            over: function(event, ui) {
                ui.draggable.remove();
            }
        });
    });
    

    Here's an updated jsFiddle.


    From a usability standpoint, I'd recommend using the drop event rather than the over event, as it would be annoying to delete an item by dragging it unintentionally over the trashcan.

提交回复
热议问题