I am trying to stack CSS keyframes (animation-delay) on the following and I am not sure how to do this programmatically?
.r1 {
animation-name: move1;
animation-delay: 0.5s;
animation-duration: 1s;
animation-iteration-count: 1;
animation-timing-function: ease-in;
animation-direction: normal;
animation-fill-mode: forwards;
}
.r2 {
animation-name: move1;
animation-delay: 1.5s;
animation-duration: 1s;
animation-iteration-count: 1;
animation-timing-function: ease-in;
animation-direction: normal;
animation-fill-mode: forwards;
}
.r3 {
animation-name: move1;
animation-delay: 2.5s;
animation-duration: 1s;
animation-iteration-count: 1;
animation-timing-function: ease-in;
animation-direction: normal;
animation-fill-mode: forwards;
}
@keyframes move1 {
to {
transform: translateX(200px);
}
}
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1280 720">
<rect class="r1" x="10" y="20" width="100" height="100" fill="red"/>
<rect class="r2" x="10" y="130" width="100" height="100" fill="green"/>
<rect class="r3" x="10" y="240" width="100" height="100" fill="blue"/>
</svg>
The animation-duration is hardcoded for each class and the animation-delay is hardcoded for the first class, i.e.r1.
How can I pass on the delay for r2 and r3, such as
r2 delay= r1 delay + r1 duration->0.5+1=1.5s
and
r3 delay= r2 delay + r2 duration ->1.5+1=2.5s
Is there anything in javascript that gives animation-duration by class?
I tried doing this by Element.getAnimations() but I am not sure if there is anything that gives animation duration by class.
I don't want to do this manually as I have a lot of class in the svg.
Thank you in advance.