jQuery Sortable - Keep it in original list

前端 未结 1 1654
野的像风
野的像风 2021-02-05 20:33

Does anyone know if jQuery UI\'s Sortable has built-in functionality to keep the original dropped item in it\'s original list?

For example, you have two lists (one \'sou

1条回答
  •  青春惊慌失措
    2021-02-05 21:14

    You can see my solution in action on jsfiddle. I simply amended this jQuery draggable/droppable interaction to suit your needs.

    HTML

    List 1

    • Drag me down
    • Drag me down

    List 2

    • Item 1
    • Item 2
    • Item 3
    • Item 4
    • Item 5

    jQuery

    $(function() {
        $("#sortable").sortable({
            revert: true
        });
        $(".draggable").draggable({
            connectToSortable: "#sortable",
            helper: "clone",
            revert: "invalid"
        });
        $("ul, li").disableSelection();
    });
    

    CSS

    .demo ul { list-style-type: none; margin: 0; padding: 0; margin-bottom: 20px; }
    .demo li { margin: 5px; padding: 5px; width: 150px; border: 1px solid black; }
    

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