Skip to content

Instantly share code, notes, and snippets.

@island205
Created July 9, 2012 05:04
Show Gist options
  • Select an option

  • Save island205/3074299 to your computer and use it in GitHub Desktop.

Select an option

Save island205/3074299 to your computer and use it in GitHub Desktop.
time animate function
animate=do ->
requestAnimationFrame = window.requestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.msRequestAnimationFrame ||
window.oRequestAnimationFrame ||
(callback)->
setTimeout(->
callback(new Date())
return
,
1000 / 60)
return
animate=(duration,callback)->
startTime=new Date()
finished=-1
step=(timestemp)->
progress=timestemp-startTime
if progress >= duration
callback(finished)
return
callback(progress)
requestAnimationFrame(step)
requestAnimationFrame(step)
return animate
animate 1000,(pro)->
if pro > 0
document.body.setAttribute "style","padding-top:"+pro/1000*100+"px"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment