Change object attribute following transition D3

attributes, d3.js, javascript, transition

Solution

According to the documentation, you can use `.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');
 });

Problem

I want to give an object an attribute once a transition is finished. I'm simply updating an images position as follows: ``` tmp.transition().duration(1000) .attr("transform", function(d) {return 'translate(' + coordinates[d].x +',' + coordinates[d].y + ')'}) ``` Once it finishes, I want to give the object tmp an attribute "moved" with the value "no". I tried: ``` tmp.transition().duration(1000) .attr("transform", function(d) {return 'translate(' + coordinates[d].x +',' + coordinates[d].y + ')'}).end('moved', 'no') ``` But without success. Any tips? Thanks,

Original source

Related problems