【发布时间】:2014-11-14 22:41:25
【问题描述】:
我从 d3.js 开始,我不明白一个奇怪的调用函数。我正在使用咖啡脚本,这是我的代码:
它不起作用:
handleTick = () ->
t += 0.01
d3.select('.ball').attr({cx: (width / 2) + 100 * Math.cos(w * t), cy: (height / 2) + 100 * Math.sin(w * t)})
d3.timer handleTick
它工作:
handleTick = () ->
t += 0.01
console.log d3.select('.ball').attr({cx: (width / 2) + 100 * Math.cos(w * t), cy: (height / 2) + 100 * Math.sin(w * t)})
d3.timer handleTick
谢谢!
【问题讨论】:
-
阅读:github.com/mbostock/d3/wiki/Transitions#d3_timer - 这两个函数的结果有何不同?请记住,与 JavaScript 不同,CoffeeScript 会自动返回最后一个表达式的值,即使没有
return。 -
我试图添加一个明确的真实回报,但仍然不是北斗
标签: animation d3.js timer attributes coffeescript