2017-09-02 108 views
0

我想知道动画路径转换是否可以返回最后绘制的位置? ..通过attrTween我们可以得到补间范围[0-1],但曲线pos?d3js 4获取路径转换的坐标

例如:

path 
    .attr("stroke-dasharray", t1 + " " + t1) 
    .attr("stroke-dashoffset", t1) 
    .transition(d3.transition() 
          .duration(lap) 
          .ease(d3.easeLinear) 
          .attrTween("e", function(d) { 
            return function(t) {}}) 
    .attr("stroke-dashoffset",0) 

感谢的

回答

0

Tween和它的工厂,可以这样定义:

function tween (t) { 
    var totalLength = this.getTotalLength(); 
    //a SVGPoint object with x/y properties 
    var position = this.getPointAtLength(total * t); 
    //...do something 
} 

function tweenFactory (d) { 
    return tween.bind(this); 
} 

如果路径已经存在于DOM当时工厂被执行并且路径长度不改变时,totalLength的计算显然可以移动到工厂功能。'

+0

Merci!我已经将attrTween切换到tween,然后放回返回函数(t)并且它工作。 – spin0