Last active
May 14, 2019 12:38
-
-
Save ogabrielguerra/9e0092ca9b57a8b1d3fbbf8095d5e676 to your computer and use it in GitHub Desktop.
Execute an action when user stops scrolling. | JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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