Reputation: 735
I am drawing the lines of an SVG using the code from here: https://github.com/dcamilleri/F1Data-Circuit-SVG-Draw.
This piece of code specifically draws a line for each SVG path.
var paths = circuit.getElementsByTagName("path");
for(var i = 0; i < paths.length; i++) {
var length = parseInt(paths[i].getTotalLength());
d3.select(paths[i])
.style("stroke-dasharray", length)
.style("stroke-dashoffset", length)
.transition()
.duration(10000)
.ease('linear')
.style("stroke-dashoffset", 0);
}
At the moment each line is drawn simultaneously over a 10 second period. What I want is to draw one line after the next is finished.
How do I do this?
Upvotes: 0
Views: 176
Reputation: 11714
You can take advantage of the transition.delay()
method which allows you to specify a delay. Because you're using i, you can probably just multiply it by the duration you have set.
d3.select(paths[i])
.style("stroke-dasharray", length)
.style("stroke-dashoffset", length)
.transition()
.duration(10000)
.delay(10000*i)
.ease('linear')
.style("stroke-dashoffset", 0);
Upvotes: 4