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 -
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);