Last active
August 29, 2015 14:02
-
-
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()".
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
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