Created
June 20, 2019 06:26
-
-
Save hrdtbs/73d1d2567d784f885bce1d53f2e1c2dd to your computer and use it in GitHub Desktop.
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
const throttle = (callback) => { | |
let throttled = false | |
return () => { | |
if(throttled) return | |
throttled = true | |
window.setTimeout(()=>{throttled = false}, 500) | |
callback() | |
} | |
} | |
document.addEventListener("scroll", throttle(()=>{ | |
console.log("hello") | |
})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment