Skip to content

Instantly share code, notes, and snippets.

@dciccale
Last active December 9, 2015 17:49
Show Gist options
  • Save dciccale/4306197 to your computer and use it in GitHub Desktop.
Save dciccale/4306197 to your computer and use it in GitHub Desktop.
requestAnimationFrame shim in 155 bytes (127 gzipped)

requestAnimationFrame shim

Cross-browser requestAnimationFrame in 155 bytes of JavaScript.

/*
* requestAnimationFrame shim
* a = window object
* b = string to re-use
*/
!function (a, b) {
// test for all vendor prefixes
// concatenating the string stored in b
// a['r' + b] = window.requestAnimationFrame
a['r' + b] = a['r' + b]
|| a['webkitR' + b] // webkit
|| a['mozR' + b] // mozilla
|| a['oR' + b] // opera
|| a['msR' + b] // internet explorer
// use a setTimeout fallback for unsupported browsers
// c = callback function
|| function (c) {
a.setTimeout(c, 1E3 / 60)
}
}(window, 'equestAnimationFrame');
!function(a,b){a["r"+b]=a["r"+b]||a["webkitR"+b]||a["mozR"+b]||a["oR"+b]||a["msR"+b]||function(c){a.setTimeout(c,1E3/60)}}(window,"equestAnimationFrame");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment