Skip to content

Instantly share code, notes, and snippets.

@renekreupl
Created July 5, 2016 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renekreupl/a65ed7d5c046249170b5d532e6fac48c to your computer and use it in GitHub Desktop.
Save renekreupl/a65ed7d5c046249170b5d532e6fac48c to your computer and use it in GitHub Desktop.
//Navigation Highlight
var sections = {},
_height = $(window).height(),
i = 0;
// Grab positions of our sections
$('section').each(function(){
sections[this.id] = $(this).offset().top;
});
$(document).scroll(function(){
var $this = $(this),
pos = $this.scrollTop();
for(i in sections){
if(sections[i] > pos && sections[i] < pos + _height){
$('a').removeClass('active');
$('.nav_' + i).addClass('active');
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment