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

120
Visualizações
Can anyone please tell me a better way of doing this?

I want to start a function only ONCE only when the user has scrolled a certain amount or a certain amount of time has passed.

right now I am doing this -

  1. setTimout for desired amount of time
  2. Clear timeout once if the user has scrolled the desired amount.
  3. and execute the function.
  4. Then clear the event listener for scroll.
const startSlides = setTimeout (() => {
    start();
}, 5000);

const doThis =  () => { debounce ( () => {
        if (window.scrollY > window.screen.height * 0.5) {
            start(); // start the animation of the slides;
            clearTimeout(startSlides);
            window.removeEventListener("scroll", doThis);
            return;
        }
    }, 200)
};
window.addEventListener ("scroll" , doThis);
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