0

How can i start one keyframes animation after other one finished?

#myDiv {
  position: relative;
  width: 100px;
  height: 100px;
  border: 1px solid;
  animation-name: animation1;
  animation-duration: 2s;
  animation-fill-mode: forwards;
}

@keyframes animation1 {
  0% {left: 100px}
  100% {left: 200px}
}

@keyframes animation2 {
  0% {top: 100px}
  100% {top: 200px}
}
<div id="myDiv"></div>

I want to animation2 start after animation1 finished. I dont want to divide one animation like 0%,50%,100% or use other animation's animation duration. I want to get animation finished information and use it. I don't want to use delay. Is it possible?

VXp
  • 11,598
  • 6
  • 31
  • 46
Furkan
  • 39
  • 7

1 Answers1

0

You could use animation-delay. If animation1 takes 3 seconds to complete, you would declare animation2 as follows

@keyframes animation2{
animation-delay : 3s;
0% {
    top: 100px;
}

100% {
    top: 200px;
}
}
Aaron Ullal
  • 4,855
  • 8
  • 35
  • 63
  • Thank but I don't want to use delay because animation duration change based on data from database and there are 5-6 animation based on each other. – Furkan Sep 04 '18 at 08:47
  • animation-delay is not a property of keyframes. If you add animation-delay to myDiv, it will delay both. – Curtis Sep 23 '19 at 19:22