Skip to content

Instantly share code, notes, and snippets.

@brettvaida
Created October 26, 2017 21:38
Show Gist options
  • Save brettvaida/59e1d03283f8a2292443ee3b022607e2 to your computer and use it in GitHub Desktop.
Save brettvaida/59e1d03283f8a2292443ee3b022607e2 to your computer and use it in GitHub Desktop.
Smooth scroll to anchor links
function scrollNav() {
$('.nav a').click(function(){
//Toggle active class
$(".active").removeClass("active");
$(this).closest('li').addClass("active");
var theClass = $(this).attr("class");
$('.' + theClass).parent('li').addClass('active');
//Animate scroll
$('html, body').stop().animate({
scrollTop: $( $(this).attr('href') ).offset().top - 70 //Offset top
}, 400);
return false;
});
$('.scrollTop a').scrollTop();
}
scrollNav();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment