jQuery UI Sortable, how to determine current location and new location in update event?

后端 未结 6 2102
太阳男子
太阳男子 2020-12-13 08:27

I have:

  • item 1
  • item 2
  • item 3
6条回答
  •  独厮守ぢ
    2020-12-13 09:10

    $('#sortable').sortable({
        start: function(e, ui) {
            // creates a temporary attribute on the element with the old index
            $(this).attr('data-previndex', ui.item.index());
        },
        update: function(e, ui) {
            // gets the new and old index then removes the temporary attribute
            var newIndex = ui.item.index();
            var oldIndex = $(this).attr('data-previndex');
            $(this).removeAttr('data-previndex');
        }
    });
    

提交回复
热议问题