Skip to content

Instantly share code, notes, and snippets.

@RoryDuncan
Created August 5, 2013 23:15
Show Gist options
  • Save RoryDuncan/6160519 to your computer and use it in GitHub Desktop.
Save RoryDuncan/6160519 to your computer and use it in GitHub Desktop.
Paul Irish's requestAnimationFrame shim in coffeescript.
lastTime = 0
vendors = ['ms', 'moz', 'webkit', 'o']
for x in vendors and not window.requestAnimationFrame
window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame']
window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame'] or
window[vendors[x]+'CancelRequestAnimationFrame']
if not window.requestAnimationFrame
window.requestAnimationFrame = (callback, element) ->
currTime = new Date().getTime()
timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) )
id = window.setTimeout ->
callback(currTime + timeToCall)
, timeToCall
lastTime = currTime + timeToCall
return id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment