Skip to content

Instantly share code, notes, and snippets.

@glassesfactory
Created May 8, 2014 02:54
Show Gist options
  • Save glassesfactory/610c672e88d6a2b37d15 to your computer and use it in GitHub Desktop.
Save glassesfactory/610c672e88d6a2b37d15 to your computer and use it in GitHub Desktop.
常日頃使っている requestAnimationFrame 対策
###*
フレーム更新時に呼ばれる
@method updateHandler
###
updateHandler =()->
console.log "some animate code..."
raf updateHandler
return
###*
requestAnimationFrame を引っ張りだす。
対応してなければ setTimeout で代替。
Chrome や Safari など最新のブラウザでも未だに
時々vendorプレフィクスを付けておかないと呼ばれないことがあるため。
@method raf
###
raf = (()->
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
(callback, element)->
#代替として setTimeout を使用している。
#式が評価されるタイミングが requestAnimationFrame と同じため。
return window.setTimeout(callback, 1000 / 60)
)()
raf updateHandler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment