aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/animation/play/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/api/animation/play/index.html')
-rw-r--r--files/zh-cn/web/api/animation/play/index.html91
1 files changed, 91 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/animation/play/index.html b/files/zh-cn/web/api/animation/play/index.html
new file mode 100644
index 0000000000..4ff52dd3c6
--- /dev/null
+++ b/files/zh-cn/web/api/animation/play/index.html
@@ -0,0 +1,91 @@
+---
+title: Animation.play()
+slug: Web/API/Animation/play
+translation_of: Web/API/Animation/play
+---
+<div>{{ APIRef("Web Animations") }}{{SeeCompatTable}}</div>
+
+<p><a href="/en-US/docs/Web/API/Web_Animations_API">Web Animations API</a>的{{ domxref("Animation") }}接口中的<strong><code>play()</code></strong> 方法 可开始或恢复动画的播放. 如果动画结束,则调用<code>play()</code>重新启动动画,从头开始播放。</p>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox">animation.play();
+</pre>
+
+<h3 id="参数">参数</h3>
+
+<p>无.</p>
+
+<h3 id="返回值">返回值</h3>
+
+<p>{{jsxref("undefined")}}</p>
+
+<h2 id="例子">例子</h2>
+
+<p>在 <a href="http://codepen.io/rachelnabors/pen/PNYGZQ?editors=0010">Growing/Shrinking Alice Game</a> 示例中, 单击或点击蛋糕会导致Alice的增长动画 (<code>aliceChange</code>) 播放,导致她体型变大并触发蛋糕的动画。在以下示例中,使用了一个事件监听器来触发两者的动画:</p>
+
+<pre class="brush: js">// 蛋糕拥有其自己的动画:
+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
+});
+
+// 暂停蛋糕的动画,以避免动画立即播放.
+nommingCake.pause();
+
+// 该函数会在用户点击时触发
+var growAlice = function() {
+
+ // Play Alice's animation.
+ aliceChange.play();
+
+ // Play the cake's animation.
+ nommingCake.play();
+
+}
+
+// 当用户持续按下或点击时, 调用 growAlice 函数使得所有的动画播放.
+cake.addEventListener("mousedown", growAlice, false);
+cake.addEventListener("touchstart", growAlice, false);
+</pre>
+
+<h2 id="标准">标准</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="浏览器兼容性">浏览器兼容性</h2>
+
+<div>
+
+
+<p>{{Compat("api.Animation.play")}}</p>
+</div>
+
+<h2 id="了解更多" style="line-height: 30px; font-size: 2.14285714285714rem;">了解更多</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")}} for other methods and properties you can use to control web page animation.</li>
+ <li>{{domxref("Animation.pause()")}} to pause an animation.</li>
+ <li>{{domxref("Animation.reverse()")}} to play an animation backwards.</li>
+ <li>{{domxref("Animation.finish()")}} to finish an animation.</li>
+ <li>{{domxref("Animation.cancel()")}} to cancel an animation.</li>
+</ul>