aboutsummaryrefslogtreecommitdiff
path: root/files/pt-br/web/api/element/animate/index.html
blob: 8c8d5e58c55aa7c1908435142448a5cb295c312a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
---
title: Element.animate()
slug: Web/API/Element/animate
translation_of: Web/API/Element/animate
---
<div>{{APIRef('Web Animations')}} {{SeeCompatTable}}</div>

<p>Um {{domxref("Element")}} de interface do método <strong><code>animate()</code></strong> é um método de atalho o qual cria uma nova {{domxref("Animation")}}, e a aplica ao elemento, então executa a animação. Retorna a instância do objeto {{domxref("Animation")}} criado.</p>

<div class="note">
<p>Elementos podem ter múltiplas animações aplicadas a eles. Você pode obter uma lista de animações que afetam um elemento chamando {{domxref("Element.getAnimations()")}}.</p>
</div>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox">var <em>animation</em> = element.animate(<em>keyframes</em>, <em>options</em>); </pre>

<h3 id="Paramêtros">Paramêtros</h3>

<dl>
 <dt><code>keyframes</code></dt>
 <dd>
 <p>An <a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API/Keyframe_Formats">Object formatted to represent a set of keyframes</a>.</p>
 </dd>
 <dt><code>opções</code></dt>
 <dd><code>Ou um inteiro representando a duração da animação (em milisegundos), ou um objeto contendo uma ou mais propriedades de tempo:</code></dd>
 <dd><code>id {{optional_inline}}</code></dd>
 <dd>
 <dl>
  <dd>Um propriedade única á animate(): uma <code><a href="https://developer.mozilla.org/en-US/docs/Web/API/DOMString" title="DOMString is a UTF-16 String. As JavaScript already uses such strings, DOMString is mapped directly to a String.">DOMString</a> com a qual a animação é referenciada.</code> </dd>
 </dl>
 {{Page("/en-US/docs/Web/API/Web_Animations_API/Animation_timing_properties", "Properties")}}</dd>
</dl>

<h4 id="Opções_Futuras">Opções Futuras</h4>

<p>As seguintes opções atualmente não são embarcadas em nenhum lugar, porém serão adicionadas num futuro próximo.</p>

<dl>
 <dt><code>composite {{optional_inline}}</code></dt>
 <dd>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.
 <ul>
  <li>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 <code>translateX(-200px) rotate(20deg)</code>.</li>
  <li>accumulate é similar porém um pouco mais inteligente: blur(2) e blur(5) se tornam blur(7), não blur(2) blur(5).</li>
  <li>replace sobreescreve o valor anterior com um novo. </li>
 </ul>
 </dd>
 <dt><code>iterationComposite {{optional_inline}}</code></dt>
 <dd>Determines how values build from iteration to iteration in this animation. Can be set to <code>accumulate</code> or <code>replace</code> (see above). Defaults to <code>replace</code>.</dd>
 <dt><code>spacing {{optional_inline}}</code></dt>
 <dd>Determina como quadros-chaves sem deslocamento temporal devem ser distribuidos durante a duração da animação. Padrão para distribute.
 <ul>
  <li>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.</li>
  <li><code>paced</code> 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.</li>
 </ul>

 <p><img alt="" src="https://w3c.github.io/web-animations/img/spacing-distribute.svg" style="height: 210px; width: 200px;"> <img alt=" " src="https://w3c.github.io/web-animations/img/spacing-paced.svg" style="height: 210px; width: 200px;"></p>
 </dd>
</dl>

<h3 id="Valor_de_retorno">Valor de retorno</h3>

<p>Retorna uma {{domxref("Animation")}}.</p>

<h2 id="Exemplo">Exemplo</h2>

<p>Na demonstração <a href="https://codepen.io/rachelnabors/pen/rxpmJL/?editors=0010">Down the Rabbit Hole (with the Web Animation API)</a>, 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.<br>
 Note o array de quadros-chave passado e também o bloco de opções de temporização.</p>

<pre class="brush: js">document.getElementById("tunnel").animate([
  // keyframes
  { transform: 'translateY(0px)' },
  { transform: 'translateY(-300px)' }
], {
  // timing options
  duration: 1000,
  iterations: Infinity
});
</pre>

<h2 id="Especificações">Especificações</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('Web Animations', '#the-animatable-interface', 'animate()' )}}</td>
   <td>{{Spec2('Web Animations')}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>

<h2 id="Compatibildade_entre_Navegadores">Compatibildade entre Navegadores</h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Edge</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari (WebKit)</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatChrome("36")}}</td>
   <td>{{CompatNo}}</td>
   <td>{{ CompatGeckoDesktop("48.0")}}</td>
   <td>{{CompatNo}}</td>
   <td>23</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>id</code> option</td>
   <td>{{CompatChrome(50.0)}}</td>
   <td>{{CompatNo}}</td>
   <td>{{ CompatGeckoDesktop("48.0")}}</td>
   <td>{{CompatNo}}</td>
   <td>37</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>composite</code>, <code>iterationComposite</code>, and <code>spacing</code> options</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Android Webview</th>
   <th>Chrome for Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>Firefox OS</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatChrome(39.0)}}</td>
   <td>{{CompatChrome(39.0)}}</td>
   <td>{{ CompatGeckoMobile("48.0")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>id</code> option</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatChrome(50.0)}}</td>
   <td>{{CompatChrome(50.0)}}</td>
   <td>{{ CompatGeckoMobile("48.0")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>composite</code>, <code>iterationComposite</code>, and <code>spacing</code> options</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="Veja_Também">Veja Também</h2>

<ul>
 <li><a href="/en-US/docs/Web/API/Web_Animations_API">Web Animations API</a></li>
 <li>{{domxref("Element.getAnimations()")}}</li>
 <li>{{domxref("Animation")}}</li>
</ul>