Skip to content

Instantly share code, notes, and snippets.

@bastianallgeier
Created December 5, 2012 09:35
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bastianallgeier/4214287 to your computer and use it in GitHub Desktop.
Save bastianallgeier/4214287 to your computer and use it in GitHub Desktop.
(function($) {
$.fn.smoothScroll = function() {
return this.on('click', function() {
var hash = $(this).attr('href');
var dest = $(hash).offset();
$('html:not(:animated),body:not(:animated)').animate({scrollTop: dest.top, scrollLeft: dest.left}, 500, function() {
window.location.hash = hash;
});
return false;
});
};
})(jQuery);
$(function() {
$('a[rel=scroll]').smoothScroll();
});
@mxlje
Copy link

mxlje commented Dec 10, 2012

This is great, thanks a lot!

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