And*_*Mao 9 javascript animation d3.js requestanimationframe
我试图弄清楚d3的默认动画requestAnimationFrame是否已用于回调,或者我是否需要自己动手.例如,我已经定义了一个自定义补间,它重复调用重绘函数,以动画在图形上从一个域转换到另一个域(这在coffeescript中):
rd = @redraw # a function that takes an argument to redraw the graph
@svg.transition()
.duration(1000)
.tween "zoom", ->
interp = d3.interpolate(current_dom, target_dom)
(t) -> rd interp(t)
Run Code Online (Sandbox Code Playgroud)
在我所有其他重绘的调用中,我安排它requestAnimationFrame:
scheduleRedraw: =>
# Stop a previous request if it hasn't executed yet
cancelAnimationFrame(@animRequest) if @animRequest
@animRequest = requestAnimationFrame => @redraw
Run Code Online (Sandbox Code Playgroud)
但是,我想知道我是否需要在这里做同样的事情.我一直在看d3源代码,看到唯一的引用requestAnimationFrame是在d3定时器类中.希望对d3有更多了解的人可以帮助回答以下问题:
requestAnimationFrame这里手动使用吗?如果没有,是否有任何我需要在使用d3时自己使用它的情况?