Created
October 7, 2012 16:22
-
-
Save JosephSilber/3848811 to your computer and use it in GitHub Desktop.
jQuery plugin to scroll to an element on the page
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 plugin to scroll to an element on the page | |
// Usage: $('#someElement').scrollTo(); | |
// or: $('#someElement').scrollTo(750); | |
(function($) | |
{ | |
var $window = $(window), | |
$document = $(document), | |
$documentWrapper = $('body, html'); | |
$.fn.scrollTo = function ( speed ) | |
{ | |
if ( speed === undefined ) speed = 300; | |
$documentWrapper.animate({ | |
scrollTop: Math.min( this.offset().top - 10, $document.height() - $window.height() ) | |
}, speed); | |
return this; | |
}; | |
}(jQuery)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The plugin is great, the only problem is that chrome doesn't seem to want to do the scrolling. FF does it without problems.