smesko85
5/29/2011 - 10:03 AM

polyfill requestAnimationFrame across browsers

polyfill requestAnimationFrame across browsers

{
  "name": "requestAnimationFrame",

  "description": "polyfill requestAnimationFrame across browsers",

  "keywords": [
    "animation",
    "requestAnimationFrame"
  ]
}
function(a,b){while(a--&&!(b=this["oR0msR0mozR0webkitR0r".split(0)[a]+"equestAnimationFrame"]));return b||function(a){setTimeout(a,15)}}(5)
// inspired by https://twitter.com/WebReflection/status/74521550245732352

function(
  a, // current cursor
  b  // placeholder
){
  while(                         // while
    a-- &&                      // the cursor is still positivel
    !(                          // and there is nothing
      b =                       // to set b to
      this[                     // on the property of the global object
        "oR0msR0mozR0webkitR0r" // which starts with the item in this list
        .split(0)               // (split on 0s)
        [a] +                   // at the cursor position
        "equestAnimationFrame"  // plus the suffix,
      ]                         // and stop when something is found.
    )
  );
  
  return b      // return either the found method
  || function(  // or otherwise a function
    a           // that takes a function
  ){
    setTimeout( // and calls
      a,        // it in
      15        // 15ms.
    )
  }
}(
  5 // iterate for the 5 items in the list.
)
            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
                    Version 2, December 2004

 Copyright (C) 2011 Jed Schmidt <http://jed.is>

 Everyone is permitted to copy and distribute verbatim or modified
 copies of this license document, and changing it is allowed as long
 as the name is changed.

            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  0. You just DO WHAT THE FUCK YOU WANT TO.