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
|
---
title: Animation.play()
slug: Web/API/Animation/play
tags:
- API
- Animacion
- Animaciones Web
- Experimental
- Interface
- Reference
- metodo
- play
- waapi
translation_of: Web/API/Animation/play
---
<div>{{ APIRef("Web Animations") }}{{SeeCompatTable}}</div>
<p>El método <strong><code>play()</code></strong> de la interfaz {{ domxref("Animation") }} de la <a href="/en-US/docs/Web/API/Web_Animations_API">Web Animations API</a> inicia o reanuda la reproducción de una animación. Si la animación ha finalizado, llamando a <code>play()</code> reinicia la animación y la reproduce desde el principio.</p>
<h2 id="Sintaxis">Sintaxis</h2>
<pre class="syntaxbox">animation.play();
</pre>
<h3 id="Parámetros">Parámetros</h3>
<p>None.</p>
<h3 id="Valor_devuelto">Valor devuelto</h3>
<p>{{jsxref("undefined")}}</p>
<h2 id="Ejemplo">Ejemplo</h2>
<p>En el ejemplo <a href="http://codepen.io/rachelnabors/pen/PNYGZQ?editors=0010">Growing/Shrinking Alice Game</a> , hacer click o tocar el pastel hace que la animación de crecimiento de Alicia (<code>aliceChange</code>) sea reproducida hacia adelante, causando que Alicia se haga más grande, ademas de desencadenar la animación del pastel. Dos <code>Animation.play()</code> y un <code>EventListener</code>:</p>
<pre class="brush: js">// El pastel tiene su propia animación:
var nommingCake = document.getElementById('eat-me_sprite').animate(
[
{ transform: 'translateY(0)' },
{ transform: 'translateY(-80%)' }
], {
fill: 'forwards',
easing: 'steps(4, end)',
duration: aliceChange.effect.timing.duration / 2
});
// Pausa la animación del pastel para que no se reproduzca inmediatamente.
nommingCake.pause();
// Esta función se reproducirá cuando el usuario haga click o toque
var growAlice = function() {
// Reproduce la animación de Alicia.
aliceChange.play();
// Reproduce la animación del pastel.
nommingCake.play();
}
// Cuando el usuario hace click o toca, llama a growAlice, para reproducir todas las animaciones.
cake.addEventListener("mousedown", growAlice, false);
cake.addEventListener("touchstart", growAlice, false);
</pre>
<h2 id="Especificaciones">Especificaciones</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', '#dom-animation-play', 'play()')}}</td>
<td>{{Spec2("Web Animations")}}</td>
<td> </td>
</tr>
</tbody>
</table>
<h2 id="Compatibilidad_del_navegador">Compatibilidad del navegador</h2>
{{Compat("api.Animation.play")}}
<h2 id="Ver_también" style="line-height: 30px; font-size: 2.14285714285714rem;">Ver también</h2>
<ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API">Web Animations API</a></li>
<li>{{domxref("Animation")}} para otros métodos y propiedades que puedes usar para el control de animaciones en páginas web.</li>
<li>{{domxref("Animation.pause()")}} para pausar una animación.</li>
<li>{{domxref("Animation.reverse()")}} para reproducir una animación al revés.</li>
<li>{{domxref("Animation.finish()")}} para finalizar una animación.</li>
<li>{{domxref("Animation.cancel()")}} para cancelar una animación.</li>
</ul>
|