1
Hello, everybody!
Which Javascript code should I insert so that when the user is browsing (scrolling) over some section the "li a" receives a new class so that the color of the link is changed?
Ideally, the "#start" section will receive the class by default and this code will work for both menus (#menu-mobile and #menu-desktop).
#menu-mobile li a, #menu-desktop li a {
color: #666666;
}
<header>
<ul id="menu-mobile">
<li><a href="#inicio" class="scroll inicio">página inicial</a>
</li>
<li><a href="#atuacao" class="scroll atuacao">área de atuação</a>
</li>
<li><a href="#portfolio" class="scroll portfolio">nosso portfolio</a>
</li>
<li><a href="#contato" class="scroll contato">entre em contato</a>
</li>
</ul>
<ul id="menu-desktop">
<li><a href="#inicio" class="scroll">página inicial</a>
</li>
<li><a href="#atuacao" class="scroll">área de atuação</a>
</li>
<li><a href="#portfolio" class="scroll">nosso portfolio</a>
</li>
<li><a href="#contato" class="scroll">entre em contato</a>
</li>
</ul>
</header
you want when the user hovers over the link it changes color?
– Giovane
No, @Giovane. I would like when he is browsing and reading something from the #contact section (for example), the "Contact" link from the menu, to have another color.
– Will
Got it, you’re looking for a component called Scrollspy
– Giovane
Exactly! But since I haven’t learned js yet, I’m hitting myself to apply this code.
– Will
Hello. I removed the tag and the mention of UX, because your question is independent of that. It may even improve (or not) the UX, but the question remains useful in general scope. :)
– Luiz Vieira