Changing a css property after a certain scroll position.

Changing a css property after a certain scroll position.

Hello everyone,

So my question is the following :


My personnal website is divided into sections that are colored with different contrasts, so as I scroll past a certain section, I need my fixed menu to change its color css property.


At first I tried to use boundingClientRect.top this way :


  1. $(function(){

  2. var projetTop = $("#projects")[0].getBoundingClientRect().top;

  3. var menuTop = $("nav")[0].getBoundingClientRect().top;

  4. $(window).scroll(function(){

  5. var calc = projetTop-menuTop;

  6. if(calc<0){

  7. $("nav a").css("color","#F6F2ED");

  8. }
  9. else{

  10. $("nav a").css("color","#696765");

  11. }
  12. });

  13. });
But it doesn't seem to work really well...


Actually, the section I'm talking about is one of the last sections on the site, and the color changing happens immediately after I start scrolling first.


Do you guys have any solutions for this problem ?


thank you very much for your future answers, and pardon my english, I'm from France ^^