Created
March 18, 2015 08:47
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.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