【发布时间】:2018-05-07 06:53:38
【问题描述】:
here 给出的示例答案适用于 D3 版本 3,但在版本 4/5 中,.each 已更改为 .on,并且该示例不再有效,即使将 .each 更改为.on。还有什么需要考虑的吗?这是 D3 版本 4 的小提琴和代码:jsfiddle
var svg = d3.select("body")
.append("svg")
.attr("width", 500)
.attr("height", 500);
// code, code, code, irrelevant code...
function timeForTimeline(){ // har
var timeline = svg.append("line")
.attr("stroke", "steelblue");
repeat();
function repeat() {
timeline.attr({
'x1': 0,
'y1': 130,
'x2': 168,
'y2': 130
})
.transition()
.duration(4000)
.ease("linear")
.attr({
'x1': 0,
'y1': 430,
'x2': 168,
'y2': 430
})
.each("end", repeat);
};
};
timeForTimeline();
【问题讨论】:
-
此代码为 D3 v3。请使用 v4/5 代码更新您的问题和小提琴,以便我们检查发生了什么。
-
另一方面,如果您的实际问题是如何为 v4/v5 更改它:1. 不要将对象放入
attr,以及 2. 更改ease值(除了each,当然)。完成后,您会看到这段代码有效。
标签: javascript loops d3.js transition