Created
April 7, 2017 13:47
-
-
Save sandroweb/43e0ff2764ab7fac0614d42e46f4509a to your computer and use it in GitHub Desktop.
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
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