Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple CSS keyframe animations using transform property not working

While working with CSS keyframe animations I found that when I give an element two animations like:

.element {     animation: animate1 1000ms linear infinite,                animate2 3000ms linear infinite; } 

If both of the animations animate using the transform property only the last one triggers through cascading. But if the @keyframes animations are lets say one margin or display or some other css attribute and the other uses transform then they both trigger.

here is a codepen example with the relevant code below.

CSS

@keyframes move {     0%, 100% { transform: translateX(0px); }     50% { transform: translateX(50px); } } @keyframes skew {     0%, 100% { transform: skewX(0deg); }     50% { transform: skewX(15deg); } } @keyframes opacity {     0%, 100% { opacity: 1; }     50% { opacity: .25; } }  .taco {     animation: skew 2000ms linear infinite,                opacity 4000ms linear infinite; } 

In the Above they both trigger

.burger {     animation: skew 2000ms linear infinite,                move 4000ms linear infinite; } 

In the above only the last triggers (through cascading)- why?

Anyone have a solution for this without using js? Or is this something that just doesn't work? The example is quite simple and I know that I could combine the animations into one and not have to declare both but this was a test for a more complex animation I was working on.

thanks

like image 747
Danferth Avatar asked Jan 17 '13 17:01

Danferth


People also ask

Can you have multiple keyframes in an animation property?

You can animate multiple properties inside a keyframe rule and use multiple keyframes to specify an element's property values at specific points in time. For example, suppose you have an element that you want to animate from one position to another, horizontally.

Why is animation not working in CSS?

Animation Duration Not Set By default, a CSS animation cycle is zero seconds long. To override this, add an animation-duration rule to your targeted element with a seconds value, in the same block as animation-name. Below, try removing the comments around animation-duration to fix the animation.

What is @- webkit keyframes in CSS?

The @keyframes rule specifies the animation code. The animation is created by gradually changing from one set of CSS styles to another. During the animation, you can change the set of CSS styles many times.


1 Answers

You cannot animate same attribute ( here transform attribute ) more than once, on a same element, the last one will overwrite other,

You should put your target element into a div, and apply one transform-animation on the div and other transform-animation on the target element....

.div_class {     animation:animate1 1000ms linear infinite; }  .element {         animation:animate2 3000ms linear infinite; } 
like image 190
Swarnendu Paul Avatar answered Sep 22 '22 08:09

Swarnendu Paul