How to remove an item that is pulled away from it's list?

前端 未结 2 822
名媛妹妹
名媛妹妹 2021-01-11 11:42

here is a simple question. I have a \'ul\' which i have made sortable via jquery-ui\'s sortable() function. I want to remove elements when they are dragged off the list.

相关标签:
2条回答
  • 2021-01-11 11:47

    I'm sure there are more than one correct way to do that but if i had to do it I would probably use a wrapper element as droppable. Why not main site container, the almighty #wrapper! Bind to drop event of the droppable and remove the item completely. It won't stay in sortable either.

    0 讨论(0)
  • 2021-01-11 12:09

    You could try to use a variable to check if the items you are dragging is dragged out of its parent container.

    You can use the over and out events of the jQuery UI sortable to assign the value for this variable and then execute the removal of the dragged item on the beforeStop event.

    here is a demo of what I have come up with: http://jsfiddle.net/drewP/m7VJq/1/

    let me know if it works for you.

    0 讨论(0)
提交回复
热议问题