I'm trying to make my fixed navigation change color when it overlaps different parts of my website. Much like the navigation on this website: http://andpizza.com/
My html exists of divs and sections.
<nav>
<ul>
<li class="work">Work</li>
<li class="about">About</li>
<li class="contact">Contact</li>
</nav>
<div id="red">
</div>
<section id="green">
</section>
<div id="blue">
</div>
<section id="yellow">
</section>
For the JS I use an overlaps library I found on github.
This jquery I added myself:
$(document).scroll(function() {
var contactColl = $('ul li.contact').overlaps('section');
$('ul li.contact')[contactColl.hits.length? 'addClass' : 'removeClass']('white');
var aboutColl = $('ul li.about').overlaps('section');
$('ul li.about')[aboutColl.hits.length? 'addClass' : 'removeClass']('white');
var workColl = $('ul li.work').overlaps('section');
$('ul li.work')[workColl.hits.length? 'addClass' : 'removeClass']('white');
});
Or view here on Codepen.
It works perfectly for the first section. But it ignores the second section. I get that it picks the first section it comes across, but I can't figure out how to make it work for the other section(s).
I tried naming the sections separately like this:
var contactColl = $('ul li.contact').overlaps('#green, #yellow');
or
var contactColl = $('ul li.contact').overlaps('#green');
$('ul li.contact')[contactColl.hits.length? 'addClass' : 'removeClass']('white');
var contactColl2 = $('ul li.contact').overlaps('#yellow');
$('ul li.contact')[contactColl2.hits.length? 'addClass' : 'removeClass']('white');
This just broke everything.
Can anybody help me with this?