Skip to content

Instantly share code, notes, and snippets.

@JosephSilber
Created October 7, 2012 16:22
Show Gist options
  • Save JosephSilber/3848811 to your computer and use it in GitHub Desktop.
Save JosephSilber/3848811 to your computer and use it in GitHub Desktop.
jQuery plugin to scroll to an element on the page
// 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));
@lorddarq
Copy link

lorddarq commented Oct 7, 2012

The plugin is great, the only problem is that chrome doesn't seem to want to do the scrolling. FF does it without problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment