Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

110
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!