【发布时间】:2012-05-28 20:07:14
【问题描述】:
class MakeCanvas
constructor : (elemId,width,height,@slideTimeThrottled) ->
@ctx = document.getElementById(elemId).getContext '2d'
@ctx.canvas.width = width
@ctx.canvas.height = height
@ctx.canvas.style.marginTop = (((height / 2) * -1)+(43 / 2))+'px'
@aniInterval = null
clearInterval @aniInterval
@frameNum = 0
drawFrame : ->
console.log 'drawFrame not overwritten'
animate : ->
clearInterval @aniInterval
@frameNum = 0
@aniInterval = setInterval (=>
@ctx.clearRect 0, 0, @ctx.canvas.width, @ctx.canvas.height
@drawFrame()
@frameNum++
@stop() if @frameNum > @slideTimeThrottled
), frameRate
stop : ->
clearInterval @aniInterval
我正在使用一个咖啡脚本类来尝试自动化画布的一些基本功能。上面的代码大部分都可以正常工作,但我真的很想开始使用requestanimationframe 而不是setInterval。
我想使用这里发布的 polyfill:https://gist.github.com/1579671
不幸的是,我只是不明白。如何重写这个类以使其功能相同并改用requestanimationframe?
【问题讨论】:
-
您对
requestAnimationFrame有什么具体问题? -
主要问题是我不知道怎么用。
标签: jquery coffeescript polyfills requestanimationframe