Skip to content

Instantly share code, notes, and snippets.

@jayllellis
Created March 4, 2015 02:49
Show Gist options
  • Save jayllellis/4386ae2fb2ae09cbbb65 to your computer and use it in GitHub Desktop.
Save jayllellis/4386ae2fb2ae09cbbb65 to your computer and use it in GitHub Desktop.
Change nav items to active as you scroll
$(window).scroll(function() {
$('section').each(function(){
var currentSection = $(this);
var currentId = $(this).attr('id');
if(currentSection.isOnScreen()){
$('.sidenav a').removeClass('active');
$('a[href="#'+currentId+'"]').addClass('active');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment