Skip to content

Instantly share code, notes, and snippets.

@Echooff3
Last active August 29, 2015 14:11
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 Echooff3/9715c1744fbdec7e495e to your computer and use it in GitHub Desktop.
Save Echooff3/9715c1744fbdec7e495e to your computer and use it in GitHub Desktop.
Update active state on scroll
$(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