Skip to content

Instantly share code, notes, and snippets.

@gyrus
Created July 21, 2012 21:28
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 gyrus/3157247 to your computer and use it in GitHub Desktop.
Save gyrus/3157247 to your computer and use it in GitHub Desktop.
Scroll to an ID
/**
* Scroll to an ID
*
* Example:
* <code>$( '#content' ).scrollView();</code>
*
* @link http://stackoverflow.com/questions/1586341/how-can-i-scroll-to-a-specific-location-on-the-page-using-jquery
*/
jQuery.fn.scrollView = function () {
return this.each( function () {
jQuery( 'html, body' ).animate({
scrollTop: jQuery( this ).offset().top
}, 1000);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment