Esta é uma tecnologia experimental
Verifique a tabela de compatibilidade entre Navegadores cuidadosamente antes de usar essa funcionalidade em produção.
Um Element
de interface do método animate()
é um método de atalho o qual cria uma nova Animation
, e a aplica ao elemento, então executa a animação. Retorna a instância do objeto Animation
criado.
Elementos podem ter múltiplas animações aplicadas a eles. Você pode obter uma lista de animações que afetam um elemento chamando Element.getAnimations()
.
Syntax
var animation = element.animate(keyframes, options);
Paramêtros
keyframes
opções
Ou um inteiro representando a duração da animação (em milisegundos), ou um objeto contendo uma ou mais propriedades de tempo:
id Optional
-
- Um propriedade única á animate(): uma
DOMString com a qual a animação é referenciada.
delay
Optional- The number of milliseconds to delay the start of the animation. Defaults to 0.
direction
Optional- 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"
. duration
Optional- 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.
easing
Optional- 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"
. endDelay
Optional- 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.
fill
Optional- 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"
. iterationStart
Optional- 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.
iterations
Optional- The number of times the animation should repeat. Defaults to
1
, and can also take a value ofInfinity
to make it repeat for as long as the element exists.
- Um propriedade única á animate(): uma
Opções Futuras
As seguintes opções atualmente não são embarcadas em nenhum lugar, porém serão adicionadas num futuro próximo.
composite Optional
- Determina como os valores são combinados entre animações diferentes, separa animações que não especificam suas próprias operações de composição. Padrão para subtitituir.
- Adiciona efeito de imposição e aditivação, onde cada iteração sucessiva é executada sobre a última. Por exemplo, com transform translateX(-200px) não sobreescreveria um valor anterior de rotate(20deg) mas resultaria em
translateX(-200px) rotate(20deg)
. - accumulate é similar porém um pouco mais inteligente: blur(2) e blur(5) se tornam blur(7), não blur(2) blur(5).
- replace sobreescreve o valor anterior com um novo.
- Adiciona efeito de imposição e aditivação, onde cada iteração sucessiva é executada sobre a última. Por exemplo, com transform translateX(-200px) não sobreescreveria um valor anterior de rotate(20deg) mas resultaria em
iterationComposite Optional
- Determines how values build from iteration to iteration in this animation. Can be set to
accumulate
orreplace
(see above). Defaults toreplace
. spacing Optional
- Determina como quadros-chaves sem deslocamento temporal devem ser distribuidos durante a duração da animação. Padrão para distribute.
- distribuir quadro-chaves de posição de forma que a diferença de deslocamento entre quadros-chaves subsequentes seja igual, distribuirá igualmente os quadros-chaves no decorrer do tempo de execução.
paced
positions keyframes so that the distance between subsequent values of a specified paced property are equal, that is to say, keyframes are spaced further apart the greater the difference in their property values.
Valor de retorno
Retorna uma Animation
.
Exemplo
Na demonstração Down the Rabbit Hole (with the Web Animation API), nós usamos o método conveniente animate() para imediamente criar e executar uma animação no elemento #tunnel para faze-lo fluir em direção superior, infinitamente.
Note o array de quadros-chave passado e também o bloco de opções de temporização.
document.getElementById("tunnel").animate([
// keyframes
{ transform: 'translateY(0px)' },
{ transform: 'translateY(-300px)' }
], {
// timing options
duration: 1000,
iterations: Infinity
});
Especificações
Specification | Status | Comment |
---|---|---|
Web Animations The definition of 'animate()' in that specification. |
Rascunho atual | Initial definition |
Compatibildade entre Navegadores
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|---|
Basic support | 36 | Não suportado | 48.0 (48.0) | Não suportado | 23 | ? |
id option |
50.0 | Não suportado | 48.0 (48.0) | Não suportado | 37 | ? |
composite , iterationComposite , and spacing options |
Não suportado | Não suportado | Não suportado | Não suportado | Não suportado | Não suportado |
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 |
Não suportado | 50.0 | 50.0 | 48.0 (48.0) | ? | ? | ? | ? |
composite , iterationComposite , and spacing options |
Não suportado | Não suportado | Não suportado | Não suportado | Não suportado | Não suportado | Não suportado | Não suportado |