Esta traducción está incompleta. Por favor, ayuda a traducir este artículo del inglés.
Esta es una tecnología experimental
Comprueba la Tabla de compabilidad de navegadores cuidadosamente antes de usarla en producción.
El método Element.animate() es un método abreviado para crear y reproducir una animación en un elemento. Devuelve la instancia creada de un objeto Animation .
Síntaxis
element.animate(keyframes, options);
Parámetros
keyframes-
Un Objeto formateado para representar un conjunto de fotogramas clave.
opciones- Puede ser un entero representando la duración de la animación (en milisegundos), o un Objeto conteniendo una o más propiedades de sincronización:
-
id OptionalUna propiedad única para animar(): aDOMStringcon la cual se hace referencia a la animación.
delayOptional- The number of milliseconds to delay the start of the animation. Defaults to 0.
directionOptional- Whether the animation runs forwards (
normal), backwards (reverse), switches direction after each iteration (alternate), or runs backwards and switches direction after each iteration (alternate-reverse). Defaults to"normal". durationOptional- The number of milliseconds each iteration of the animation takes to complete. Defaults to 0. Although this is technically optional, keep in mind that your animation will not run if this value is 0.
easingOptional- The rate of the animation's change over time. Accepts the pre-defined values
"linear","ease","ease-in","ease-out", and"ease-in-out", or a custom"cubic-bezier"value like"cubic-bezier(0.42, 0, 0.58, 1)". Defaults to"linear". endDelayOptional- The number of milliseconds to delay after the end of an animation. This is primarily of use when sequencing animations based on the end time of another animation. Defaults to 0.
fillOptional- Dictates whether the animation's effects should be reflected by the element(s) prior to playing (
"backwards"), retained after the animation has completed playing ("forwards"), orboth. Defaults to"none". iterationStartOptional- Describes at what point in the iteration the animation should start. 0.5 would indicate starting halfway through the first iteration for example, and with this value set, an animation with 2 iterations would end halfway through a third iteration. Defaults to 0.0.
iterationsOptional- The number of times the animation should repeat. Defaults to
1, and can also take a value ofInfinityto make it repeat for as long as the element exists.
Opciones Futuras
Las siguientes opciones actualmente no se han enviado a todos los sitios, pero se añadirán en un futuro próximo.
composite Optional- Determina como se combinan los valores entre esta animación y otra, animaciones independientes sin especificar la composición de su propia operación.
Valores predeterminados a reemplazar.añadir dicta un efecto aditivo, donde cada iteración sucesiva se basa en la anterior. Por ejemplo contransform, atranslateX(-200px)no anularía un valor anteriorrotate(20deg)que resultaríatranslateX(-200px) rotate(20deg).acumular es similar pero un poco más inteligente:blur(2)yblur(5)resultaríablur(7), noblur(2) blur(5).remplazar sobreescribe el valor anterior con el nuevo.
iterationComposite Optional- Determina como se construyen los valores de una iteración a otra en esta animación. .
Se puede configurar para acumular o reemplazar(ver arriba).Valores predeterminados para reemplazar. spacing Optional- Determina como los keyframes sin compensación temporal deben ser distribuidos durante la duración de la animación.
Valores predeterminados para distribuir.distribuir las posiciones de loskeyframes para que la diferencia entre el anterior y el posterior estén compensadas por igual , lo que es como decir, sin ninguna compensación, esto distribuirá equitativamente los keyframes a traves del tiempo de ejecución.situar las posiciones de loskeyframes de manera que igualen la diferencia entre los siguientes valores de una propiedad especifica sincronizada , lo que es como decir, que los keyframes estén más espaciados cuanto mayores sean los valores de sus propiedades.
Valor de retorno
Returns an Animation.
Ejemplo
En la demostración Down the Rabbit Hole (con la Web Animation API), utilizamos el método conveniente, animate() para inmediatamente crear y ejecutar una animación en el elemento #tunnel para hacerlo fluir hacia arriba, indefinidamente. Observar el orden de paso de los objetos por los keyframes y también el bloque de opciones de sincronización.
document.getElementById("tunnel").animate([
// keyframes
{ transform: 'translateY(0px)' },
{ transform: 'translateY(-300px)' }
], {
// timing options
duration: 1000,
iterations: Infinity
});
Especificaciones
| Specification | Status | Comment |
|---|---|---|
| Web Animations La definición de 'animate()' en esta especificación. |
Working Draft | Initial definition |
Compatibilidad en los Navegadores
| Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
|---|---|---|---|---|---|---|
| Basic support | 36 | ? | 48.0 (48.0) | ? | 23 | ? |
id option |
50.0 | ? | 48.0 (48.0) | ? | 37 | ? |
composite, iterationComposite, and spacing options |
Sin soporte | Sin soporte | Sin soporte | Sin soporte | Sin soporte | Sin soporte |
| Feature | Android | Android Webview | Chrome for Android | Firefox Mobile (Gecko) | Firefox OS | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|---|---|
| Basic support | ? | 39.0 | 39.0 | 48.0 (48.0) | ? | ? | ? | ? |
id option |
Sin soporte | 50.0 | 50.0 | 48.0 (48.0) | ? | ? | ? | ? |
composite, iterationComposite, and spacing options |
Sin soporte | Sin soporte | Sin soporte | Sin soporte | Sin soporte | Sin soporte | Sin soporte | Sin soporte |