Skip to content

Instantly share code, notes, and snippets.

@RolandVels
Created December 8, 2016 09:45
Show Gist options
  • Save RolandVels/439a4210596d024ba2a230058cdf0fe6 to your computer and use it in GitHub Desktop.
Save RolandVels/439a4210596d024ba2a230058cdf0fe6 to your computer and use it in GitHub Desktop.
smoothScroll
smoothScroll(1000);
function smoothScroll (duration) {
$('a[href^="#"]').on('click', function(event) {
var target = $( $(this).attr('href') );
if( target.length ) {
event.preventDefault();
$('html,body').animate({
scrollTop: target.offset().top
}, duration);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment