I want to get a stage animation
I went all the path to svg
and through setTimeout I want to take turns to draw them
But I can't do it.
let path = document.querySelectorAll("svg path");
path.forEach(function (el, index){
let nl = el.getTotalLength();
el.setAttribute("stroke-dasharray", `0 ${nl}`);
setTimeout(function (){
el.setAttribute("stroke-dasharray", `${nl} ${nl}` + index);
},2400)
})
path{
fill: none;
stroke: red;
stroke-width: 2;
}
<svg viewBox="0 0 300 120" width="300">
<path d="M20,30 100,30 290,0" />
<path d="M20,50 100,50 290,17" />
<path d="M20,70 100,70 290,34" />
<path d="M20,90 100,90 290,51" />
<path d="M20,110 100,110 290,68" />
</svg>
In my case, it turns out that all path are drawn at the same time .. And it is necessary separately
I want to get the effect of drawing a line like in smil with animate - in which lines are drawn in turn when using stroke-dasharray in javascript
https://codepen.io/topicstarter/pen/gOPMEWw
Teach how to do it