Skip to content Skip to sidebar Skip to footer

Jquery Class Change Based On Scroll Ignoring Last Section

I'm using jQuery to guide my pages scrolling and change the color of a nav item to correspond to the section you're in. Everything's working well, but the script is ignoring the l

Solution 1:

I think the following line is where the problem lies:

if(top > topsArray[i] && topsArray[i+1] && top < topsArray[i+1]){

Specifically topsArray[i+1] is undefined for the last iteration of i. Try pushing one more value into topsArray that includes the height of the entire page.

topsArray = $sections.map(function(){
               return $(this).position().top - 100;
            }).get(),
topsArray.push(document.height);

Post a Comment for "Jquery Class Change Based On Scroll Ignoring Last Section"