Tironemota

CSS

Propiedades CSS Animación
17-08-2022

animation 17-08-2022

La propiedad animation es una propiedad abreviada para:

Nota: especifique siempre la propiedad animation-duration (duración de la animación); de lo contrario, la duración es 0 y nunca se reproducirá.

Valor por defecto: none 0 ease 0 1 normal none running

Sintaxis de JavaScript: object.style.animation="mymove 5s infinite"

Sintaxis CSS: animation: name duration timing-function delay iteration-count direction fill-mode play-state;

Valores de propiedad:

  • animation-name Especifica el nombre del keyframe que desea vincular al selector
  • animation-duration Especifica cuántos segundos o milisegundos tarda una animación en completarse
  • animation-timing-function Especifica la curva de velocidad de la animación.
  • animation-delay Especifica un retraso antes de que comience la animación.
  • animation-iteration-count Especifica cuántas veces se debe reproducir una animación.
  • animation-direction Especifica si la animación debe reproducirse o no en reversa en ciclos alternativos
  • animation-fill-mode Especifica qué valores aplica la animación fuera del tiempo que se está ejecutando
  • animation-play-state Especifica si la animación se está ejecutando o está en pausa
  • initial Establece esta propiedad en su valor predeterminado.
  • inherit Hereda esta propiedad de su elemento padre.
animation: none
<div id="padre">
    <div id="movil1">Propiedad<br>animation</div>
</div>
#padre { height:300px; width:400px; }
#movil1{ background:red; position:relative;
    height:50px; width:150px;
    -webkit-animation: none; /* Safari 4.0 - 8.0 */
    animation: ;
}
@-webkit-keyframes ........ Ver ejemplos
Propiedad
animation

@keyframes 17-08-2022

La regla @keyframes especifica el código de animación.

La animación se crea cambiando gradualmente de un conjunto de estilos CSS a otro.

Durante la animación, puede cambiar el conjunto de estilos CSS muchas veces.

Especifique cuándo ocurrirá el cambio de estilo en porcentaje, o con las palabras clave "from" y "to", que es lo mismo que 0% y 100%. 0% es el comienzo de la animación, 100% es cuando la animación se completa.

Consejo: para obtener el mejor soporte del navegador, siempre debe definir los selectores 0% y 100%.

Sintaxis CSS: @keyframes nombre-de-la-animación {keyframes-selector {css-styles;}}

Valores de propiedad:

  • nombre-de-la-animación - Necesario. Define el nombre de la animación.
  • keyframes-selector - Necesario. Porcentaje de la duración de la animación.
    Valores legales:
    0-100%
    from (igual que 0%)
    to (igual que el 100%)
    Nota: Puede tener muchos fotogramas-selectores en una animación.
  • css-styles - Necesario. Una o más propiedades de estilo CSS legales.
@-webkit-keyframes movil1
/* Safari 4.0 - 8.0 */
@-webkit-keyframes movil1 {
    0%   { top: 0px; }
    25%  { top: 200px; }
    75%  { top: 50px; }
    100% { top: 100px; }
}
/* Sintaxis estándar */
@keyframes movil1 {
    0%   { top: 0px; }
    25%  { top: 200px; }
    75%  { top: 50px; }
    100% { top: 100px; }
}
@-webkit-keyframes movil2
/* Safari 4.0 - 8.0 */
@-webkit-keyframes movil2 {
    0%   { top: 0px;   background: red;    width: 100px; }
    100% { top: 200px; background: yellow; width: 350px; }
}
/* Sintaxis estándar */
@keyframes movil2 {
    0%   { top: 0px;   background: red;    width: 100px; }
    100% { top: 200px; background: yellow; width: 350px; }
}
@-webkit-keyframes movil3
/* Safari 4.0 - 8.0 */
@-webkit-keyframes movil3 {
    0%   { top: 0px;   left: 0px;   background: red; }
    25%  { top: 0px;   left: 250px; background: blue; }
    50%  { top: 250px; left: 250px; background: yellow; }
    75%  { top: 250px; left: 0px;   background: green; }
    100% { top: 0px;   left: 0px;   background: red; }
}
/* Sintaxis estándar */
@keyframes movil3 {
    0%   { top: 0px;   left: 0px;   background: red; }
    25%  { top: 0px;   left: 250px; background: blue; }
    50%  { top: 250px; left: 250px; background: yellow; }
    75%  { top: 250px; left: 0px;   background: green; }
    100% { top: 0px;   left: 0px;   background: red; }
}
@-webkit-keyframes movil4
/* Safari 4.0 - 8.0 */
@-webkit-keyframes movil4 {
    from { left: 0px; }
    to   { left: 250px; }
}
/* Sintaxis estándar */
@keyframes movil4 {
    from { left: 0px; }
    to   { left: 250px; }
}

animation-delay 17-08-2022

Especifica un retardo para el inicio de una animación. El valor de retardo de animación se define en segundos (s) o milisegundos (ms).

Valor por defecto: 0s

Sintaxis de JavaScript: object.style.animationDelay="1s"

Sintaxis: animation-delay: tiempo | initial | inherit;

Valores de propiedad:

  • tiempo - Opcional. Define el número de segundos o milisegundos (ms) que debe esperar antes de que comience la animación. El valor predeterminado es 0. Se permiten valores negativos.
  • initial - Establece esta propiedad a su valor predeterminado.
  • inherit - Hereda esta propiedad de su elemento padre.

Nota: La propiedad animation-delay no es compatible con Internet Explorer 9 y versiones anteriores.

animation-direction 17-08-2022

La propiedad animation-direction define si una animación debe reproducirse en sentido inverso o en ciclos alternos.

Valor por defecto: normal

Sintaxis de JavaScript: object.style.animationDirection="reverse"

Sintaxis CSS: animation-direction: normal | reverse | alternate | alternate-reverse | initial | inherit;

Valores de propiedad:

  • normal - Valor por defecto. La animación debe ser jugada como normal.
  • reverse - La animación debe jugar en sentido inverso.
  • alternate - La animación se reproducirá de forma normal cada vez que se desee (1,3,5, etc.) y en sentido inverso cada tiempo par (2,4,6, etc ...).
  • alternate-reverse - La animación se reproducirá en dirección inversa a cada instante impar (1,3,5, etc.) y en una dirección normal cada tiempo par (2,4,6, etc ...).
  • initial - Establece esta propiedad a su valor predeterminado.
  • inherit - Hereda esta propiedad de su elemento padre.

Nota: La propiedad animation-direction no es compatible con Internet Explorer 9 y versiones anteriores.

Nota: Los valores "reverso" y "alterno-reverso" no son compatibles con Safari.

animation-direction: normal
<div id="padre">
    <div id="movil1">Propiedad<br>animation</div>
</div>
#padre { height:300px; width:400px; }
#movil1{ background:red; height:50px;
    position:relative; width:150px;
    -webkit-animation:movil3 5s infinite;
    animation: movil3 5s infinite;
    -webkit-animation-direction: normal; /* Safari 4.0 - 8.0 */
    animation-direction: ;
}
/* Safari 4.0 - 8.0 */
@-webkit-keyframes movil3 {
    0%   { top: 0px;   left: 0px;   background: red; }
    25%  { top: 0px;   left: 250px; background: blue; }
    50%  { top: 250px; left: 250px; background: yellow; }
    75%  { top: 250px; left: 0px;   background: green; }
    100% { top: 0px;   left: 0px;   background: red; }
}
/* Sintaxis estándar */
@keyframes movil3 {
    0%   { top: 0px;   left: 0px;   background: red; }
    25%  { top: 0px;   left: 250px; background: blue; }
    50%  { top: 250px; left: 250px; background: yellow; }
    75%  { top: 250px; left: 0px;   background: green; }
    100% { top: 0px;   left: 0px;   background: red; }
}
Propiedad
animation

animation-duration 17-08-2022

La propiedad animation-duration define cuántos segundos o milisegundos una animación tarda en completar un ciclo.

Valor por defecto: 0

Sintaxis de JavaScript: object.style.animationDuration="3s"

Sintaxis CSS: animation-duration: tiempo | initial | inherit;

Valores de propiedad:

  • tiempo - Especifica la longitud que tarda una animación en terminar. El valor predeterminado es 0, lo que significa que no habrá animación.
  • initial - Establece esta propiedad a su valor predeterminado.
  • inherit - Hereda esta propiedad de su elemento padre.

Nota: La propiedad animation-duration no es compatible con Internet Explorer 9 y versiones anteriores.

Nota: Siempre especifique la propiedad animation-duration. De lo contrario, la duración es 0 y la animación no se reproducirá.

animation-duration: 0s
<div id="padre">
    <div id="movil1">Propiedad<br>animation</div>
</div>
#padre { height:300px; width:400px; }
#movil1{ background:red; height:50px;
    position:relative; width:150px;
    -webkit-animation:movil3 0s infinite;
    animation: movil3 0s infinite;
    -webkit-animation-duration: 0; /* Safari 4.0 - 8.0 */
    animation-duration: ;
}
/* Safari 4.0 - 8.0 */
@-webkit-keyframes movil3 {
    0%   { top: 0px;   left: 0px;   background: red; }
    25%  { top: 0px;   left: 250px; background: blue; }
    50%  { top: 250px; left: 250px; background: yellow; }
    75%  { top: 250px; left: 0px;   background: green; }
    100% { top: 0px;   left: 0px;   background: red; }
}
/* Sintaxis estándar */
@keyframes movil3 {
    0%   { top: 0px;   left: 0px;   background: red; }
    25%  { top: 0px;   left: 250px; background: blue; }
    50%  { top: 250px; left: 250px; background: yellow; }
    75%  { top: 250px; left: 0px;   background: green; }
    100% { top: 0px;   left: 0px;   background: red; }
}
Propiedad
animation

animation-fill-mode 17-08-2022

La propiedad animation-fill-mode especifica un estilo para el elemento cuando la animación no se está reproduciendo (cuando está terminado o cuando tiene un retardo).

De forma predeterminada, las animaciones CSS no afectan al elemento hasta que se reproduce el primer fotograma clave y, a continuación, se detiene una vez que se ha completado el último fotograma clave. La propiedad animation-fill-mode puede anular este comportamiento.

Valor por defecto: 0

Sintaxis: animation-fill-mode: none | forwards | backwards | both | initial | inherit;

Valores de propiedad:

  • none - Valor por defecto. La animación no aplicará ningún estilo al elemento de destino antes o después de ejecutarlo.
  • forwards - Una vez finalizada la animación (determinada por la animation-iteration-count), la animación aplicará los valores de propiedad para el tiempo en que terminó la animación.
  • backwards - La animación aplicará los valores de propiedad definidos en el fotograma clave que iniciará la primera iteración de la animación, durante el período definido por animation-delay. Estos son los valores del fotograma clave (cuando la dirección de la animación es "normal" o "alternate") o los del fotograma clave (cuando animation-direction es "reverse" o "alternate-reverse").
  • both - La animación seguirá las reglas tanto para adelante como para atrás. Es decir, extenderá las propiedades de animación en ambas direcciones.
  • initial - Establece esta propiedad a su valor predeterminado.
  • inherit - Hereda esta propiedad de su elemento padre.

Nota: La propiedad animationFillMode sólo se admite en Firefox.

animation-iteration-count 17-08-2022

La propiedad animation-iteration-count especifica el número de veces que se debe reproducir una animación.

Valor por defecto: 1

Sintaxis: animation-iteration-count: número | infinite | initial | inherit;

Valores de propiedad:

  • número - Un número que define cuántas veces se debe reproducir una animación. El valor predeterminado es 1.
  • infinite - Especifica que la animación se debe reproducir infinitas veces (para siempre).
  • initial - Establece esta propiedad a su valor predeterminado.
  • inherit - Hereda esta propiedad de su elemento padre.

animation-name 17-08-2022

La propiedad animation-name especifica un nombre para la animación @keyframes.

Nota: La propiedad animation-name no es compatible con Internet Explorer 9 y versiones anteriores.

Nota: Siempre especifique la propiedad animation-duration. De lo contrario, la duración es 0 y la animación no se reproducirá.

Valor por defecto: none

Sintaxis: animation-name: keyframe-nombre | none | initial | inherit;

Valores de propiedad:

  • keyframe-nombre - Especifica el nombre del fotograma clave al que desea enlazar el selector.
  • none - Valor por defecto. Especifica que no habrá animación (puede utilizarse para anular las animaciones procedentes de la cascada).
  • initial - Establece esta propiedad a su valor predeterminado.
  • inherit - Hereda esta propiedad de su elemento padre.
animation-name: none
<div id="padre">
    <div id="movil1">Propiedad<br>animation</div>
</div>
#padre { height:300px; width:400px; }
#movil1{ background:red; height:50px;
    position:relative; width:150px;
    -webkit-animation-duration: 5s;
    animation-duration: 5s;
    -webkit-animation-name: none; /* Safari 4.0 - 8.0 */
    animation-name: ;
}
@-webkit-keyframes ........ Ver ejemplos
Propiedad
animation

animation-play-state 17-08-2022

La propiedad animation-play-state especifica si la animación se está ejecutando o pausada.

Nota: Utilice esta propiedad en JavaScript para detener una animación en el centro de un ciclo.

Valor por defecto: running

Sintaxis: animation-play-state: paused | running | initial | inherit;

Valores de propiedad:

  • paused - Especifica que la animación está pausada.
  • running - Valor por defecto. Especifica que la animación se está ejecutando.
  • initial - Establece esta propiedad a su valor predeterminado.
  • inherit - Hereda esta propiedad de su elemento padre.
animation-play-state: running
<div id="padre">
    <div id="movil1">Propiedad<br>animation</div>
</div>
#padre { height:300px; width:400px; }
#movil1{ background:red; height:50px;
    position:relative; width:150px;
    -webkit-animation: movil3 5s infinite;
    animation: movil3 5s infinite;
    -webkit-animation-play-state: running; /* Safari 4.0 - 8.0 */
    animation-play-state: ;
}
/* Safari 4.0 - 8.0 */
@-webkit-keyframes movil3 {
    0%   {top: 0px; left: 0px; background: red;}
    25%  {top: 0px; left: 250px; background: blue;}
    50%  {top: 250px; left: 250px; background: yellow;}
    75%  {top: 250px; left: 0px; background: green;}
    100% {top: 0px; left: 0px; background: red;}
}
/* Standard syntax */
@keyframes movil3 {
    0%   {top: 0px; left: 0px; background: red;}
    25%  {top: 0px; left: 250px; background: blue;}
    50%  {top: 250px; left: 250px; background: yellow;}
    75%  {top: 250px; left: 0px; background: green;}
    100% {top: 0px; left: 0px; background: red;}
}
Propiedad
animation

animation-timing-function 17-08-2022

La función animation-timing-function especifica la curva de velocidad de una animación.

La curva de velocidad define el TIEMPO que una animación utiliza para cambiar de un conjunto de estilos CSS a otro.

La curva de velocidad se utiliza para realizar los cambios sin problemas.

Valor por defecto: ease

Sintaxis: animation-timing-function: linear | ease | ease-in | ease-out | ease-in-out | step-start | step-end | steps(int,start | end) | cubic-bezier(n,n,n,n) | initial | inherit;

La función de sincronización de animación utiliza una función matemática, denominada curva Cubic Bezier, para realizar la curva de velocidad. Puede utilizar sus propios valores en esta función o utilizar uno de los valores predefinidos:

Valores de propiedad:

  • linear - La animación tiene la misma velocidad de principio a fin.
  • ease - Valor por defecto. La animación tiene un inicio lento, luego rápido, antes de que termine lentamente.
  • ease-in - La animación tiene un comienzo lento.
  • ease-out - La animación tiene un final lento.
  • ease-in-out - La animación tiene un inicio lento y un final lento.
  • step-start - Equivalente a las etapas (1, inicio).
  • step-end - Equivalente a las etapas (1, final).
  • steps(int,start | end) - Especifica una función paso a paso, con dos parámetros. El primer parámetro especifica el número de intervalos en la función. Debe ser un entero positivo (mayor que 0). El segundo parámetro, que es opcional, es el valor "start" o "end", y especifica el punto en el que ocurre el cambio de valores dentro del intervalo. Si se omite el segundo parámetro, se le da el valor "end".
  • cubic-bezier(n,n,n,n) - Defina sus propios valores en la función cubic-bezier. Los valores posibles son valores numéricos de 0 a 1.
  • initial - Establece esta propiedad a su valor predeterminado.
  • inherit - Hereda esta propiedad de su elemento padre.

Nota: La propiedad animation-timing-function no es compatible con Internet Explorer 9 y versiones anteriores.

Ejemplo animación 1 17-08-2022

Colocar puntero sobre los cuadrantes para que roten

Primer cuadrante

Segundo cuadrante

<div class="rotador">
    <div>
        <h2>Primer cuadrante</h2>
        <img src="URL-IMAGEN" alt=""/>
    </div>
    <div>
        <h2>Segundo cuadrante</h2>
        <img src="URL-IMAGEN" alt=""/>
    </div>
</div>
.rotador{
    background:#585757;
    border-radius:0.5em;
    box-sizing:border-box;
    margin:20px auto;
    padding:1em;
    vertical-align:top;
    width:100%;
    display:flex;
    justify-content:space-around;
}
.rotador div{
    background:#FFF;
    border-radius:0.5em;
    display:inline-block;
    margin:0;
    min-height:200px;
    padding:0.5em;
    text-align:center;
    text-shadow:2px 2px 5px rgba(0,0,0,0.7);
    transition:all 1s linear;
    -khtml-transition:all 1s linear;
    -moz-transition:all 1s linear;
    -ms-transition:all 1s linear;
    -o-transition:all 1s linear;
    -xv-transition:all 1s linear;
    -wap-transition:all 1s linear;
    -webkit-transition:all 1s linear;
    vertical-align:top;
    width:40%
}
.rotador div:hover{
    background:#FDDDA8;
    transform:rotate(4deg);
    -khtml-transform:rotate(4deg);
    -moz-transform:rotate(4deg);
    -ms-transform:rotate(4deg);
    -o-transform:rotate(4deg);
    -xv-transform:rotate(4deg);
    -wap-transform:rotate(4deg);
    -webkit-transform:rotate(360deg);
}

Ejemplo animación 2 17-08-2022

Posa el puntero sobre los textos

<div class="animacion2">
    <p><a href="#">Primero</a></p>
    <p><a href="#">Segundo</a></p>
    <p><a href="#">Tercero</a></p>
    <p><a href="#">Cuarto</a></p>
</div>
.animacion2{
    height:200px;
    width:300px;
    margin:auto;
    background-color:#333;
    text-align:center;
    padding:20px;
}
.animacion2 a{
    font-size:24px;
    color:#CCC;
    text-shadow:0px 0px 0px #f00;
    text-decoration:none;
}
.animacion2 a:hover{
    color:#FFF;
    letter-spacing:8px;
    text-shadow:0px 0px 12px #fff;
    -moz-transition-duration:1s; /* Mozilla Firefox */
    -webkit-transition-duration:1s; /* Chrome y Safari */
    -o-transition-duration:1s; /* Opera */
    -ms-transition-duration:1s; /* Internet Explorer */
    transition-duration:1s;
}

Ejemplo animación 3 17-08-2022

Posa el puntero sobre este texto
<div class="animacion3">Posa el puntero sobre este texto</div>
.animacion3{
    text-align:center;
    width:400px;
    /* Aqui colocamos la transicion para cada navegador */
    -webkit-transition:all 1s ease-out; /* Chrome y Safari */
    -o-transition:all 1s ease-out; /* Opera */
    -moz-transition:all 1s ease-out; /* Mozilla Firefox */
    -ms-transition:all 1s ease-out; /* Internet Explorer */
    transition:all 1s ease-out;
}
.animacion3:hover{
    width:450px;
    color: #FFF;
    background-color: #333;
    letter-spacing: 5px;
}

Ejemplo animación 4 17-08-2022

Posa el puntero sobre este texto
<div class="animacion4">Posa el puntero sobre este texto</div>
.animacion4{
    text-align:center;
    width:400px;
    /* Aqui colocamos la transicion para cada navegador */
    -webkit-transition:all 1s ease-out; /* Chrome y Safari */
    -o-transition:all 1s ease-out; /* Opera */
    -moz-transition:all 1s ease-out; /* Mozilla Firefox */
    -ms-transition:all 1s ease-out; /* Internet Explorer */
    transition:all 1s ease-out; /* W3C */
}
.animacion4:hover{
    text-shadow:0 0 20px black;
    color:#555;
    box-shadow:0 0 10px 0 black;
}

Ejemplo animación 5 17-08-2022

Pose el puntero sobre las imagenes

img1 img2 img3 img4 img5
<table class="animaciontabla">
    <tr>
        <td><img src="URL-IMAGEN" width="50" height="50" alt="img1" class="animacion5"/></td>
        <td><img src="URL-IMAGEN" width="50" height="50" alt="img2" class="animacion5"/></td>
        <td><img src="URL-IMAGEN" width="50" height="50" alt="img3" class="animacion5"/></td>
        <td><img src="URL-IMAGEN" width="50" height="50" alt="img4" class="animacion5"/></td>
        <td><img src="URL-IMAGEN" width="50" height="50" alt="img5" class="animacion5"/></td>
    </tr>
</table>
.animaciontabla{
    margin:auto;
    border-collapse:collapse;
}
.animaciontabla td{
    border:1px solid #000000;
    padding:12px
}
.animacion5{
    display:block!important;
    -webkit-transition:-webkit-transform 1s ease-out;
    -moz-transition:-moz-transform 1s ease-out;
    -o-transition:-o-transform 1s ease-out;
    -ms-transition:-ms-transform 1s ease-out;
    transition:transform 1s ease-out;
}
.animacion5:hover{
    -moz-transform: scale(1.5);
    -webkit-transform: scale(1.5);
    -o-transform: scale(1.5);
    -ms-transform: scale(1.5);
    transform: scale(1.5)
}

Ejemplo animación 6 17-08-2022

Pose el puntero sobre las imagenes

img1 img2 img3 img4 img5
<table class="animaciontabla">
    <tr>
        <td><img src="URL-IMAGEN" width="50" height="50" alt="img1" class="animacion6"/></td>
        <td><img src="URL-IMAGEN" width="50" height="50" alt="img2" class="animacion6"/></td>
        <td><img src="URL-IMAGEN" width="50" height="50" alt="img3" class="animacion6"/></td>
        <td><img src="URL-IMAGEN" width="50" height="50" alt="img4" class="animacion6"/></td>
        <td><img src="URL-IMAGEN" width="50" height="50" alt="img5" class="animacion6"/></td>
    </tr>
</table>
.animaciontabla{
    margin:auto;
    border-collapse:collapse;
}
.animaciontabla td{
    border:1px solid #000000;
    padding:12px
}
.animacion6{
    float:left;
    display:block!important;
    -webkit-transition:-webkit-transform 1s ease-out;
    -moz-transition:-moz-transform 1s ease-out;
    -o-transition:-o-transform 1s ease-out;
    -ms-transition:-ms-transform 1s ease-out;
    transition:transform 1s ease-out;
}
.animacion6:hover{
    position:relative;
    top:-20px;
    -moz-transform: scale(1.9);
    -webkit-transform: scale(1.9);
    -o-transform: scale(1.9);
    -ms-transform: scale(1.9);
    transform: scale(1.9);
}

Ejemplo animación 7 17-08-2022

img1 img2 img3 img4 img5
<table class="animacion7">
    <tr>
        <td><img src="URL-IMAGEN" alt="img1"/></td>
        <td><img src="URL-IMAGEN" alt="img2"/></td>
        <td><img src="URL-IMAGEN" alt="img3"/></td>
        <td><img src="URL-IMAGEN" alt="img4"/></td>
        <td><img src="URL-IMAGEN" alt="img5"/></td>
    </tr>
</table>
.animacion7{
    margin:auto;
    border-collapse:collapse;
}
.animacion7 td{
    border:1px solid #000000;
    padding:12px
}
.animacion7 img{
    height:50px;
    width:auto;
    display:block!important;
    position: relative;
    -webkit-transition:-webkit-transform 1s ease-out;
    -moz-transition:-moz-transform 1s ease-out;
    -o-transition:-o-transform 1s ease-out;
    -ms-transition:-ms-transform 1s ease-out;
    transition:transform 1s ease-out;
}
.animacion7 img:hover{
    cursor:pointer;
    z-index: 10;
    -moz-transform: scale(10);
    -webkit-transform: scale(10);
    -o-transform: scale(10);
    -ms-transform: scale(10);
    transform: scale(10);
}