Skip to content

Instantly share code, notes, and snippets.

@musaid
Created October 9, 2018 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save musaid/93e44a939cb1cc3dda8a9f0274f37b49 to your computer and use it in GitHub Desktop.
Save musaid/93e44a939cb1cc3dda8a9f0274f37b49 to your computer and use it in GitHub Desktop.
$(function() {
$('#sortable').sortable({
start: function(event, ui) {
var start_pos = ui.item.index();
ui.item.data('start_pos', start_pos);
},
change: function(event, ui) {
var start_pos = ui.item.data('start_pos');
var index = ui.placeholder.index();
if (start_pos < index) {
$('#sortable li:nth-child(' + index + ')').addClass('highlights');
} else {
$('#sortable li:eq(' + (index + 1) + ')').addClass('highlights');
}
},
update: function(event, ui) {
$('#sortable li').removeClass('highlights');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment