我试着一个接一个地画汉字的笔画。要做到这一点,“在i的末尾,启动转换i+1",我使用each("end", animateSO(code,i+1)),其中animateSO以增量的方式回调自己。
// Animate strokes function
var animateSO = function(code, i){
var id= "#kvg\\:"+code+"-s"+i,
next=i+1;
var path = d3.select(id);
var totalLength = Math.ceil( path.node().getTotalLength() );
console.log("i: "+i+" ; id: "+id+" ; lenght: "+totalLength+"; i++: "+next);
path
.attr("stroke-dasharray", totalLength + " " + totalLength)
.attr("stroke-dashoffset", totalLength)
.transition()
.duration(totalLength*15)
.ease("linear")
.attr("stroke-dashoffset", 0)
.each("end", animateSO(code, next));
}
animateSO("07425", 1);我预计.each("end", animateSO(code, next))会在当前过渡的end上触发。但是所有的转变都是一起开始的。
How to, “在i的末尾,开始过渡i+1" ”
Fiddle: http://jsfiddle.net/0v7jjpdd/4/
编辑:最终结果http://jsfiddle.net/0v7jjpdd/7/
发布于 2015-02-03 13:19:50
您需要将对animateSO的调用放入函数中,否则将与其余代码一起调用它:
.each("end", function() { animateSO(code, next) });完整的演示这里。
https://stackoverflow.com/questions/28299028
复制相似问题