转换完成后,我想为对象提供属性。我只是在更新图像位置,如下所示:
tmp.transition().duration(1000)
.attr("transform", function(d) {return 'translate(' +
coordinates[d].x +',' +
coordinates[d].y + ')'})
完成后,我想为对象tmp提供一个值为“no”的“moved”属性。我试过了:
tmp.transition().duration(1000)
.attr("transform", function(d) {return 'translate(' +
coordinates[d].x +',' +
coordinates[d].y + ')'}).end('moved', 'no')
但是没有成功。有小费吗?谢谢,
最佳答案
根据the documentation,您可以使用.each
:
tmp.transition().duration(1000)
.attr("transform", function(d) {return 'translate(' +
coordinates[d].x +',' +
coordinates[d].y + ')'}
).each('end', function() {
d3.select(this).attr('moved', 'no');
// or maybe also this.setAttribute('moved', 'no');
});