How to make dynamic animations with CSS3?

6

I can do animations with transition, rotate +: hover or triggering class change with JS.

But what if I want an animation in CSS3 that when rendered makes more than one movement without being 'limited to a pair of keys'?

ps: At the moment I am looking for solutions that do not require the use of jQuery or any other lib. For the sake of making the application more "raw" and light.

    
asked by anonymous 07.12.2014 / 02:59

1 answer

7

Just complementing what you've already found there for the galley you do not know yet.

Animations in CSS3 can be created using the @keyframes property, which purpose is a very powerful property.

It can be defined as follows:

@keyframes nome_da_animacao {
    /* Passos */
    from {
        /* Estado inicial */
    }
    to {
        /* Estado final */
    }
}

You can still set the steps for the animation as a percentage instead of from and to

@keyframes nome_da_animacao {
    /* Passos */
    0% {
        /* Estado inicial */
    }
    50% {
        /* Estado aos 50% da animação */
    }
    100% {
        /* Estado final */
    }
}

Just after creating your animation, to add it to the element, just use the animation .

#elemento {
    /* nome_da_animacao + propriedades */
    animation: nome_da_animacao 1s infinite;
}

According to the documentation in MDN the animation property has the following settings:

Unfortunately, you still need to use prefixes to work well on most modern browsers; Both in the animation declaration, and when to apply to the element.

Here is an example animation using @keyframes : link

Great article in CSS Tricks talking about: link

    
08.12.2014 / 12:27