jQuery UI Sortable Position

后端 未结 4 1808
小蘑菇
小蘑菇 2020-12-07 08:03

How do I track what position an element is when its position in a sortable list changes?

4条回答
  •  [愿得一人]
    2020-12-07 08:50

    I wasn't quite sure where I would store the start position, so I want to elaborate on David Boikes comment. I found that I could store that variable in the ui.item object itself and retrieve it in the stop function as so:

    $( "#sortable" ).sortable({
        start: function(event, ui) {
            ui.item.startPos = ui.item.index();
        },
        stop: function(event, ui) {
            console.log("Start position: " + ui.item.startPos);
            console.log("New position: " + ui.item.index());
        }
    });
    

提交回复
热议问题