diff options
Diffstat (limited to 'files/zh-cn/web/api/animation/finish/index.html')
-rw-r--r-- | files/zh-cn/web/api/animation/finish/index.html | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/animation/finish/index.html b/files/zh-cn/web/api/animation/finish/index.html new file mode 100644 index 0000000000..527c8f78ce --- /dev/null +++ b/files/zh-cn/web/api/animation/finish/index.html @@ -0,0 +1,97 @@ +--- +title: Animation.finish() +slug: Web/API/Animation/finish +tags: + - API + - Animation + - Finish + - Interface + - Methos + - Web Animations +translation_of: Web/API/Animation/finish +--- +<p>{{APIRef("Web Animations")}}{{SeeCompatTable}}</p> + +<div> +<p><span class="seoSummary">The <strong><code>finish()</code> </strong>method of the <a href="/en-US/docs/Web/API/Web_Animations_API">Web Animations API</a>'s {{domxref("Animation")}} Interface sets the current playback time to the end of the animation corresponding to the current playback direction.</span> That is, if the animation is playing forward, it sets the playback time to the length of the animation sequence, and if the animation is playing in reverse (having had its {{domxref("Animation.reverse", "reverse()")}} method called), it sets the playback time to 0.</p> +</div> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox"><em>Animation</em>.finish(); </pre> + +<h3 id="参数">参数</h3> + +<p>None.</p> + +<h3 id="返回值">返回值</h3> + +<p>None.</p> + +<dl> +</dl> + +<h3 id="异常">异常</h3> + +<dl> + <dt><code>InvalidState</code></dt> + <dd>The player's playback rate is 0 or the animation's playback rate is greater than 0 and the end time of the animation is infinity.</dd> +</dl> + +<h2 id="例子"><strong>例子</strong></h2> + +<p>The following example shows how to use the <code>finish()</code> method and catch an <code>InvalidState</code> error.</p> + +<pre class="brush: js">interfaceElement.addEventListener("mousedown", function() { + try { + player.finish(); + } catch(e if e instanceof InvalidState) { + console.log("finish() called on paused or finished animation."); + } catch(e); + logMyErrors(e); //pass exception object to error handler + } +}); +</pre> + +<p>The following example finishes all the animations on a single element, regardless of their direction of playback.</p> + +<pre class="brush: js">elem.getAnimations().forEach( + function(animation){ + return animation.finish(); + } +); +</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-finish', 'finish()')}}</td> + <td>{{Spec2("Web Animations")}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div> + + +<p>{{Compat("api.Animation.finish")}}</p> +</div> + +<h2 id="更多参考" style="line-height: 30px; font-size: 2.14285714285714rem;">更多参考</h2> + +<ul> + <li><a href="/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.play()")}} to play an animation forward.</li> + <li>{{domxref("Animation.reverse()")}} to play an animation backward.</li> +</ul> |