Last active
April 9, 2016 13:36
-
-
Save VoidVolker/81e2c8dfeef64b9f98c713586c571070 to your computer and use it in GitHub Desktop.
Best jQuery scrollTo script, forked from http://lions-mark.com/jquery/scrollTo/
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
$.fn.scrollTo = function( target, options, callback ){ | |
if(typeof options == 'function' && arguments.length == 2){ callback = options; options = target; } | |
var settings = { | |
scrollTarget : target, | |
offsetTop : options && options.offsetTop || 0, | |
duration : options && options.duration || 500 , | |
easing : options && options.easing || 'swing' | |
}; | |
return this.each(function(){ | |
if ( this.isScrollingTo !== true) { | |
var scrollPane = $(this); | |
var scrollTarget = (typeof settings.scrollTarget == "number") ? settings.scrollTarget : $(settings.scrollTarget); | |
var scrollY = (typeof scrollTarget == "number") ? scrollTarget : scrollTarget.offset().top + scrollPane.scrollTop() - settings.offsetTop - scrollPane.offset().top; | |
this.isScrollingTo = true; | |
scrollPane.animate({scrollTop : scrollY }, parseInt(settings.duration), settings.easing, function(){ | |
this.isScrollingTo = false; | |
if (typeof callback == 'function') { callback.call(this); } | |
}); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment