Last active
August 29, 2015 14:11
-
-
Save Echooff3/9715c1744fbdec7e495e to your computer and use it in GitHub Desktop.
Update active state on 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
$(function() { | |
var industriesResizeTimeout; | |
var lastElementScrolled = ''; | |
$(window).on('scroll', function () { | |
var last = undefined; | |
$('a[name]').each(function () { | |
if(($(window).scrollTop() - ($(this).offset().top-155)) > 0) { | |
last = $(this).attr('name'); | |
} | |
}); | |
if( lastElementScrolled != last && last ) { | |
lastElementScrolled = last; | |
$('.menu > li').removeClass('active'); | |
$('li').removeClass('active'); | |
$('li a[href=#' + last + ']').parent().addClass('active'); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment