Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Have an element with 2 CSS Animations executing at the same time

I am experimenting with WebKits animations.

Is it possible for a HTML element to have more than one animation executing at the same time?

For example:

    @-webkit-keyframes FADE 
    {
       from {
          opacity: 0;
       }
       to {
          opacity: 1;
       }
    }

    @-webkit-keyframes TRICKY 
    {
       0% {
          -webkit-transform: translate(0px,0) rotate(-5deg) skew(-15deg,0);
       }
       50% {
          -webkit-transform: translate(-100px,0) rotate(-15deg) skew(-25deg,0);
       }
       75% {
          -webkit-transform: translate(-200px,0) rotate(-5deg) skew(-15deg,0);
       }
       100% {
          -webkit-transform: translate(0px,0) rotate(0) skew(0,0);
       }
    }

// Can this element have FADE execute for 5 seconds BUT halfway between that animation
// can I then start the TRICKY animation & make it execute for 2.5 seconds?
#myEle {
    -Webkit-animation-name: FADE TRICKY;
    -Webkit-animation-duration: 5s 2.5s;
}

The above was a really simple example. I would have many libraries of animations such as rotate, fade, etc. And I dont want to have to write a special animation if I want to have an element execute 2 animations at the same time.

Is this possible...

//Not sure if this is even valid CSS: can I merge 2 animations easily like this?
@-webkit-keyframes FADETRICKY
{
   FADE TRICKY;
}
like image 285
sazr Avatar asked Nov 30 '11 04:11

sazr


People also ask

Can an element have multiple animations CSS?

Setting multiple animation property valuesThe CSS animation longhand properties can accept multiple values, separated by commas. This feature can be used when you want to apply multiple animations in a single rule and set different durations, iteration counts, etc., for each of the animations.

Can you have multiple keyframes in CSS?

Property Values Percentage of the animation duration. Note: You can have many keyframes-selectors in one animation.


1 Answers

#myEle {
    -Webkit-animation-name: FADE,TRICKY;
    -Webkit-animation-duration: 5s,2.5s;
}

Use ',' no space. I was in Chrome version 16.0.899.0 to try.

like image 112
lemon郑 Avatar answered Oct 14 '22 09:10

lemon郑