Created
October 1, 2015 17:57
-
-
Save taniarascia/b29626e3f2e8e8e9c3cb to your computer and use it in GitHub Desktop.
Active Scroll
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
var sections = $('section'), | |
links = $('nav ul li a'), | |
lis = $('nav ul > li'); | |
$(window).scroll(function() { | |
var currentPosition = $(this).scrollTop(); | |
links.removeClass('active'); | |
lis.removeClass('active'); | |
sections.each(function() { | |
var top = $(this).offset().top, | |
bottom = top + $(this).height(); | |
if (currentPosition >= top && currentPosition <= bottom) { | |
var link = $('a[href="#' + this.id + '"]'); | |
link.addClass('active-color'); | |
link.parent().addClass('active'); | |
} else { | |
link = $('a[href="#' + this.id + '"]'); | |
link.removeClass('active-color'); | |
link.parent().removeClass('active'); | |
} | |
}); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment