jQuery Sortable - Keep it in original list

前端 未结 1 1655
野的像风
野的像风 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

    <div class="demo">
        <h2>List 1</h2>
        <ul>
            <li class="draggable ui-state-highlight">Drag me down</li>
            <li class="draggable ui-state-highlight">Drag me down</li>
        </ul>
        <h2>List 2</h2>
        <ul id="sortable">
            <li class="ui-state-default">Item 1</li>
            <li class="ui-state-default">Item 2</li>
            <li class="ui-state-default">Item 3</li>
            <li class="ui-state-default">Item 4</li>
            <li class="ui-state-default">Item 5</li>
        </ul>
    </div>
    

    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)
提交回复
热议问题