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

249
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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