Skip to content

Instantly share code, notes, and snippets.

@nilghe
Created March 18, 2015 08:47
Show Gist options
  • Save nilghe/967a435d6305533d603d to your computer and use it in GitHub Desktop.
Save nilghe/967a435d6305533d603d to your computer and use it in GitHub Desktop.
Very simple smooth scrolling to another anchor on the page. Taking into account the header height.
$('.scroll-to').on('click', function(){
var anchor = $(this).attr('href');
var height = $('.header').height(); // If the header is fixed
$('html, body').animate({
scrollTop: $(anchor).offset().top - height
}, 400);
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment