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

247
Vistas
Smooth scroll polyfill not working inside a forEach loop

I'm using the smooth scroll polyfill npm package https://github.com/iamdustan/smoothscroll on a website I'm developing and despite trying for hours, I can't get it working. After importing and invoking the package I'm calling a function that adds an event listener to all links with a data attribute of "navigate-to" so that the appropriate element would be scrolled into view. Does anyone have any ideas what could be causing the problem? I suspect it might have something to do with the addeventlistener being appliead inside a forEach? Thanks in advance!

    import smoothscroll from "smoothscroll-polyfill";
    smoothscroll.polyfill();

    function anchorScrollTo() {
     document.querySelectorAll("[data-navigateTo]").forEach(function (e) {
     e.addEventListener("click", function (event) {
      document.querySelector(e.dataset.navigateto).scrollIntoView({ behaviour: "smooth" });
    });
  });
}
     anchorScrollTo()
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

After trying a few more solutions, I noticed that for some reason the polyfill doesn't work with querySelectorAll, so I just created an array of classes that I loop through and select each of the elements with querySelector instead.

about 4 years ago · Juan Pablo Isaza Denunciar
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