Skip to content

Instantly share code, notes, and snippets.

@rsl
Last active August 29, 2015 14:04
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 rsl/4e98deb7f347cd7d0c8e to your computer and use it in GitHub Desktop.
Save rsl/4e98deb7f347cd7d0c8e to your computer and use it in GitHub Desktop.
Page scroll fix for jQuery Sortable [http://johnny.github.io/jquery-sortable/ not jQuery UI version]
$('#foo').xsortable({
onDrag: function ($item, position, _super, event) {
var $window = $(window);
var itemTop = $item.offset().top;
if (itemTop > ($window.scrollTop() + $window.height())) {
if (!window.lastItemTop || (itemTop > window.lastItemTop)) {
window.scrollBy(0, 10);
}
} else if (itemTop < $window.scrollTop()) {
if (!window.lastItemTop || (itemTop < window.lastItemTop)) {
window.scrollBy(0, -10);
}
}
window.lastItemTop = itemTop;
$item.css(position);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment