Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

283
Vistas
What am I doing wrong that window on scroll event is not been called up?

I am trying to add an EventListener to my window object and toggle an active class when scrolling. But the event is never fired, what could be the problem?

 window.addEventListener('scroll', () => {
  let current = '';

  section.forEach(section => {
    const sectionTop = section.offsetTop;
    const sectionHeight = section.clientHeight;
    if (pageYOffset >= sectionTop) {
      current = section.getAttribute('id');
    }
  });

  navli.forEach(li => {
    li.classList.remove('active');
    if (li.classList.contains(current)) {
      li.classList.add('active');
    }
  });
});

Below is the HTML code

   <nav>
        <div class="navigation">
            <ul>
                <li class="home active"><a href="#home">Home</a></li>
                <li class="about"><a href="#about">About</a></li>
                <li class="service"><a href="#service">Services</a></li>
                <li class="work"><a href="#work">Work</a></li>
                <li class="contact"><a href="#contact">Contact</a></li>
            </ul>
        </div>
    </nav>
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda