Last active
August 29, 2015 14:04
-
-
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]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#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