I'm attempting to create a script that changes the colour of the navigation bar if the nav is currently hovered over a part of the page that has a light/white background to keep the nav visible.
I want to change the colour of the hamburger menu which is laid out like so:
<div id="nav_ham" onclick="openNav()">
    <span class=""></span>
    <span class=""></span>
    <span class=""></span>
    <span class=""></span>
</div> 
To change the colour of the spans, I want to add a class ham_dark which does the following:
.ham_dark { background: #000!important;} 
I've given the white backgrounds a class of section_white and have applied the following code:
//CHANGES COLOR OF NAV ON WHITE SECTIONS
function onScreen() {
    // Check if the top of the page collides with each section
    jQuery('.section_white').each(function() {
        var windowScroll = jQuery(document).scrollTop();
        var navHeight = jQuery('.nav').height();
    // Complex line checks if windowScroll (top of page) + nav bar hits Section Top / Bottom
        if( windowScroll + navHeight >= jQuery(this).offset().top && windowScroll + navHeight <= jQuery(this).offset().top + jQuery(this).height()) {
            // This section is active! Add Highlight
            console.log('working');
            jQuery('#nav_ham span').addClass('ham_dark')
        } else {
            // No - Remove highlight class
            jQuery('#nav_ham span').removeClass('ham_dark')
        }
    });
}
jQuery(window).on('scroll resize', function () {
    onScreen();
});
The console is logging "working" when the nav is hovering over all of the the section_white classes, however it only applies the addClass to the final section_white class on the page, ignoring all others.
Why is it that the console.log is firing on all of the classes but only applying the addClass to the final instance of section_white?
I have mocked this up and the error is still occuring (nav changes colour on final section_white div but not the first): jsfiddle
Thanks
 
    