Skip to content

Instantly share code, notes, and snippets.

@ogabrielguerra
Last active May 14, 2019 12:38
Show Gist options
  • Save ogabrielguerra/9e0092ca9b57a8b1d3fbbf8095d5e676 to your computer and use it in GitHub Desktop.
Save ogabrielguerra/9e0092ca9b57a8b1d3fbbf8095d5e676 to your computer and use it in GitHub Desktop.
Execute an action when user stops scrolling. | JS
let scroller=(callback, interval)=>{
//Inits the var
let scrollStop;
//Adds the event listener
window.addEventListener('scroll', function () {
clearTimeout(scrollStop);
scrollStop = setTimeout(function () {
//Execute the callback passed as reference
callback();
}, interval);
})
};
let callMe = ()=>{
console.log('I was invocked');
}
scroller(callMe, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment