Skip to content

Instantly share code, notes, and snippets.

@james2doyle
Last active September 29, 2016 22:43
Show Gist options
  • Save james2doyle/2c0ddd5c0aba56131f8179c1894ce72d to your computer and use it in GitHub Desktop.
Save james2doyle/2c0ddd5c0aba56131f8179c1894ce72d to your computer and use it in GitHub Desktop.
Window resize event listener with an added delay. This stops the resize event from firing constantly while resizing. Basically a debounce for scrolling
function someNamedFunction() {
// fires 200 ms after the last scroll event
}
function handleResize() {
clearTimeout(this.delayer);
this.delayer = setTimeout(someNamedFunction, 200);
}
window.addEventListener('resize', handleResize);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment