Skip to content

Instantly share code, notes, and snippets.

@notgiorgi
Created August 4, 2017 12:43
Show Gist options
  • Save notgiorgi/95de16427d36871b4c25fefcde127c2a to your computer and use it in GitHub Desktop.
Save notgiorgi/95de16427d36871b4c25fefcde127c2a to your computer and use it in GitHub Desktop.
function optimizeEvent(type, obj = window) {
let running = false
obj.addEventListener(type, () => {
if (running) { return; }
running = true;
requestAnimationFrame(() => {
obj.dispatchEvent(new CustomEvent(`optimized-${type}`))
running = false;
})
})
}
optimizeEvent("resize")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment