Skip to content

Instantly share code, notes, and snippets.

@tybruffy
Created July 3, 2014 17:45
Show Gist options
  • Save tybruffy/606c6831152f01e76a09 to your computer and use it in GitHub Desktop.
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
$.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