Skip to content

Instantly share code, notes, and snippets.

@zenman
Created February 19, 2014 18:28
Show Gist options
  • Save zenman/9098336 to your computer and use it in GitHub Desktop.
Save zenman/9098336 to your computer and use it in GitHub Desktop.
Easy jquery scrollTo anchor
jQuery(function($) {
var scrollElement = 'html, body';
$("a[href^='#']").click(function(event) {
event.preventDefault();
var $this = $(this),
target = this.hash,
$target = $(target);
$(scrollElement).stop().animate({
'scrollTop': $target.offset().top
}, 1000, 'swing', function() {
window.location.hash = target;
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment