Menu

gitpiper

onScrollStop javascript Code Snippet in 2022

browsereventintermediate

Last Updated: 28 December 2022

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; window.addEventListener( 'scroll', e => { clearTimeout(isScrolling); isScrolling = setTimeout(() => { callback(); }, 150); }, false ); };
onScrollStop(() => { console.log('The user has stopped scrolling'); });

javascript snippet similar to onScrollStop For You in December 2022

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2022 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️