Handle scroll stop

JavaScript, Browser, Event · Jan 6, 2021

Runs the callback whenever the user has stopped scrolling.

  • Use EventTarget.addEventListener() to listen for the 'scroll' event.
  • Use setTimeout() to wait 150 ms until calling the given callback.
  • Use clearTimeout() to clear the timeout if a new 'scroll' event is fired in under 150 ms.
const onScrollStop = callback => {
  let isScrolling;
    e => {
      isScrolling = setTimeout(() => {
      }, 150);
onScrollStop(() => {
  console.log('The user has stopped scrolling');

Written by Angelos Chalaris

I'm Angelos Chalaris, a JavaScript software engineer, based in Athens, Greece. The best snippets from my coding adventures are published here to help others learn to code.

If you want to keep in touch, follow me on GitHub or Twitter.

More like this

  • JavaScript Event Handling

    Event handling needs to be done right in JavaScript. Pick up some tips and tricks to create a better user experience.

    Collection · 15 snippets

  • Handle user input change

    Runs the callback whenever the user input type changes (mouse or touch).

    JavaScript, Browser · Oct 21, 2020

  • Handle click outside

    Runs the callback whenever the user clicks outside of the specified element.

    JavaScript, Browser · Jan 6, 2021

  • Add multiple listeners

    Adds multiple event listeners with the same handler to an element.

    JavaScript, Browser · Oct 22, 2020