Cross-browser requestAnimationFrame in 155 bytes of JavaScript.
Last active
December 9, 2015 17:49
-
-
Save dciccale/4306197 to your computer and use it in GitHub Desktop.
requestAnimationFrame shim in 155 bytes (127 gzipped)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!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