Created
May 8, 2014 02:54
-
-
Save glassesfactory/610c672e88d6a2b37d15 to your computer and use it in GitHub Desktop.
常日頃使っている requestAnimationFrame 対策
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
###* | |
フレーム更新時に呼ばれる | |
@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