Created
July 3, 2014 17:45
-
-
Save tybruffy/606c6831152f01e76a09 to your computer and use it in GitHub Desktop.
Simple jQuery plugin to scroll the browser to the position of a jQuery element
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.elScroll = function(settings) { | |
var defaults = { | |
duration: 600, | |
queue: false, | |
offset: 0, | |
} | |
var options = $.extend(true, {}, defaults, settings); | |
var callback = options.complete || function() {}; | |
delete options.complete; | |
return this.each(function() { | |
var scrollTo = $(this).offset().top - options.offset; | |
var animation = $("html, body").stop().animate({ | |
scrollTop: scrollTo | |
}, options); | |
$.when(animation).done(function() { | |
callback.call($(this)); | |
}); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment