Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

251
Visualizações
How to change text color on different section using js or jquery

I have created a page with different background colors. What I'm trying to achieve is to change color fixed nav links on different sections. Like I've given custom class of light and dark respectively to the sections. And want to change color of nav links as the sections scrolls.

I'm a newbie to js and jquery, please let me know how can i achive this, I'm getting ideas to how to do, but i'm not able to execute it (or write it in a proper way)

This is what I have yet

<div class="nav">
  <ul>
    <li><a href="#" class="nav-link">Home</a></li>
    <li><a href="#" class="nav-link">About</a></li>
    <li><a href="#" class="nav-link">FAQ</a></li>
    <li><a href="#" class="nav-link">Contact Us</a></li>
  </ul>
</div>
<div class="one m-light"></div>
<div class="two m-dark"></div>
<div class="three m-light"></div>
<div class="four m-dark"></div>

<style>
 .nav{
  position:fixed;
}

.nav li {
  display: inline-block;
  list-style: none;
  height: 60px; /* should be the same as line-height */
  line-height: 60px;
  padding: 0 40px; 
}
.nav-link {
  color: #000;
  text-decoration: none;
  mix-blend-mode:difference !important;
}

.one, .two, .three, .four{
  height:100vh;
  width:100%;
}

.one{
  background:#f1f1f1;
}
.two{
  background:#050505;
}
.three{
  background:#f4f4f4;
}

.four{
  background:#030303;
} 
</style>

<script>

$(document).ready(function(){       
        var scroll_pos = 0;
        var darkSection = $('.m-dark')
        $(document).scroll(function() { 
            scroll_pos = $(this).scrollTop();
            if(darkSection > scroll_pos) {
                $('.nav-link').css('color', '#000');
            } else {
                $('.nav-link').css('color', '#fff');
            }
        });
    });

</script>

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda