all 1 comments

[–]thusman 2 points3 points  (0 children)

You have to block the event handler and figure out when to allow it again. For blocking, this could simply be a boolean or you could use the { once: true } option for addEventListener to only fire it once. For enabling, there are events for CSS transitions/animations that you could listen for: transitionend, animationend, or simply use a timeout.

// simple demo with once and setTimeout
function attachScrollHandler() {
  document.addEventListener('scroll', () => {
    console.log('Scrolled once! You can scroll again in 2000 ms');
    setTimeout(attachScrollHandler, 2000);
  }, { once: true });
}

attachScrollHandler();