EventTarget.addEventListener()
to listen for the 'scroll'
event.setTimeout()
to wait 150
ms until calling the given callback
.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');
});
Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️