Skip to content

Instantly share code, notes, and snippets.

@pavelbinar
Last active December 27, 2015 23:19
Show Gist options
  • Save pavelbinar/7405312 to your computer and use it in GitHub Desktop.
Save pavelbinar/7405312 to your computer and use it in GitHub Desktop.
JavaScript: Smooth scrolling
// Smooth scrolling
// Source: http://www.paulund.co.uk/smooth-scroll-to-internal-links-with-jquery
$('a[href^="#"]').on('click',function (e) {
e.preventDefault();
var target = this.hash,
$target = $(target);
$('html, body').stop().animate({
'scrollTop': $target.offset().top
}, 900, 'swing', function () {
window.location.hash = target;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment