Skip to content

Instantly share code, notes, and snippets.

@ehpc
Last active August 29, 2015 14:02
Show Gist options
  • Save ehpc/7861cb5871057a484c02 to your computer and use it in GitHub Desktop.
Save ehpc/7861cb5871057a484c02 to your computer and use it in GitHub Desktop.
"Scroll to" plugin for jQuery. Automatically scrolls to selected element, usage: "$('#mydiv").scrollTo()".
jQuery.fn.extend({
/**
* Smooth scrolling to element
* @param interval Scrolling interval
* @param offset Offset from an element
*/
scrollTo: function (interval, offset) {
'use strict';
if (typeof interval === 'undefined') {
interval = 1000;
}
if (typeof offset === 'undefined') {
offset = -50;
}
jQuery('html, body').animate({
scrollTop: jQuery(this).offset().top + offset
}, interval);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment