Skip to content

Instantly share code, notes, and snippets.

@bendc
Created August 18, 2016 20:28
Show Gist options
  • Save bendc/8e109434c5ef94310ecca9dfbc0f2e28 to your computer and use it in GitHub Desktop.
Save bendc/8e109434c5ef94310ecca9dfbc0f2e28 to your computer and use it in GitHub Desktop.
Better setInterval
const interval = (callback, delay) => {
const tick = now => {
if (now - start >= delay) {
start = now;
callback();
}
requestAnimationFrame(tick);
};
let start = performance.now();
requestAnimationFrame(tick);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment