Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Timing CSS animation events

I’m having trouble figuring out how to time the execution of events. In this case, the div should slide down from the top, and then grow by 10%. I tried stacking the animations, as a best guess, but this doesn’t work.

@keyframes slideDown {
  0% {
    transform: translateY(-100%);
  }

  100% {
    transform: translateY(0);
  }
}

@keyframes grow {
  0% {
    transform: scale(1);
  }

  100% {
    transform: scale(1.1);
  }
}
    
#theDiv {
  animation-name: slideDown grow;
  animation-duration: 3s 3s;  
  animation-fill-mode: forwards forwards;
  animation-timing-function: ease ease;
  transition-delay: 0s 3s;
  
  padding: 50px;
  background-color: yellow
}
<div id="theDiv">HELLO, WORLD!</div>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You can’t use transform atttibute with multiple animation. If you call both of animation "slideDown" and "grow", it only applying "grow" animation.

So if you want animate "grow" after "slideDown", merge both anmiation.

@keyframes stacked-anim {
  0% {
    transform: translateY(-100%);
  }
  50% {
    transform: translateY(0) scale(1);
  }
  100% {
    transform: scale(1.1);
  }
}

#theDiv {
  animation-name: stacked-anim;
  animation-duration: 6s;
  animation-fill-mode: forwards;
  animation-timing-function: ease;
  padding: 50px;
  background-color: yellow;
}
<div id="theDiv">HELLO, WORLD!</div>

If you animate different attributes, you can set multiple animation with comma.

@keyframes grow {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

@keyframes changeColor {
  0% {
    background-color: yellow;
  }
  100% {
    background-color: crimson;
  }
}

#theDiv {
  animation-name: changeColor, grow;
  animation-duration: 3s, 3s;
  animation-fill-mode: forwards, forwards;
  animation-timing-function: ease, ease;
  padding: 50px;
  background-color: yellow;
}
<div id="theDiv">HELLO, WORLD!</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading