Skip to content

Instantly share code, notes, and snippets.

@klauskpm
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klauskpm/f865cbc705bd3485a9a4 to your computer and use it in GitHub Desktop.
Save klauskpm/f865cbc705bd3485a9a4 to your computer and use it in GitHub Desktop.
jQuery plugin to animate and scroll to it's destination.
// jQuery Plugin - ScrollToMe
//
// Needs:
// - jQuery(2.1.1) >> http://code.jquery.com/jquery-2.1.1.js
(function($) {
/**
* Plugin to scroll the page till it element
* @param {Object.<(string|integer), string>} options Object with
* duration time(duration) and animation style(easing)
* @returns {jQuery.this}
*/
$.fn.scrollToMe = function(options) {
var settings = $.extend({duration: 500, easing: 'linear'}, options);
$('html, body').animate(
{scrollTop: this.offset().top},
settings.duration,
settings.easing
);
return this;
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment