Skip to content

Instantly share code, notes, and snippets.

@v0lkan
Last active May 5, 2018 16:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save v0lkan/796206f7e420fec4b973fd6c7ccab4f3 to your computer and use it in GitHub Desktop.
Save v0lkan/796206f7e420fec4b973fd6c7ccab4f3 to your computer and use it in GitHub Desktop.
Double requestAnimatioFrame FTW!
const rafraf = (callback) => {
if (!window.requestAnimationFrame) {return null;}
return window.requestAnimationFrame(() =>
window.requestAnimationFrame(callback)
);
};
@v0lkan
Copy link
Author

v0lkan commented May 5, 2018

I deleted the description in the comments because it was not telling the whole story, and it’s harder to write things than to show it since the root of the problem is related to time, timing, loops, queues, events and things like that; which can better be explained visually than in written form.

Besides there are few variationns on the theme that shows when you might (and when you might not) need a double requestAnimationFrame which, again, can be better expressed in an audio-visual form showing all the dev tool and profiler outputs.

I’m recording a screencast about it: I will link to the video when it’s done.

Until then… May the source be with you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment