Skip to content

Instantly share code, notes, and snippets.

@corysimmons
Last active January 3, 2018 16:08
Show Gist options
  • Save corysimmons/4f86d56aa46517437147 to your computer and use it in GitHub Desktop.
Save corysimmons/4f86d56aa46517437147 to your computer and use it in GitHub Desktop.
John Resig - Learning from Twitter Tiny JS Throttle
let didResize = false
window.addEventListener(`resize`, () => {
didResize = true
})
setInterval(() => {
if (didResize) {
// Do stuff
didResize = false
}
}, 250)
let didScroll = false
window.addEventListener(`scroll`, () => {
didScroll = true
})
setInterval(() => {
if (didScroll) {
// Do stuff
didResize = false
}
}, 250)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment