Skip to content

Instantly share code, notes, and snippets.

@sandroweb
Created April 7, 2017 13:47
Show Gist options
  • Save sandroweb/43e0ff2764ab7fac0614d42e46f4509a to your computer and use it in GitHub Desktop.
Save sandroweb/43e0ff2764ab7fac0614d42e46f4509a to your computer and use it in GitHub Desktop.
function animateVerticalScroll(px, scope, callback, options) {
var time,
callbackCalled = false,
obj;
options = options || {};
options.time = options.time || 1000;
currScroll = scope.scrollTop();
scope = scope || $('body, html');
scope.removeClass('scroll-touch');
obj = scope ? { scrollTop: px } : { 'scroll-top': px };
if (currScroll > px) {
time = (currScroll - px) * options.time / 1000;
} else {
time = (px - currScroll) * options.time / 1000;
}
scope.stop().animate(obj, time, function () {
if (callbackCalled === false) {
callbackCalled = true;
scope.addClass('scroll-touch');
if (typeof callback === 'function') {
callback();
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment