Skip to content

Instantly share code, notes, and snippets.

@dbani-dev
Forked from bendc/interval.js
Created August 19, 2016 02:33
Show Gist options
  • Save dbani-dev/daff48d6ec0330b9eeae5b232268a46f to your computer and use it in GitHub Desktop.
Save dbani-dev/daff48d6ec0330b9eeae5b232268a46f 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