--- title: Animation.cancel() slug: Web/API/Animation/cancel tags: - Animation.cancel() translation_of: Web/API/Animation/cancel ---

{{ SeeCompatTable() }}{{ APIRef("Web Animations") }}

{{domxref("Animation")}} 接口的 Web动画API的 cancel() 方法将清除此动画造成的所有{{domxref("KeyframeEffect")}} ,并中止其播放。.

当一个动画被取消时,其  {{domxref("Animation.startTime", "startTime")}}  和{{domxref("Animation.currentTime", "currentTime")}} 被设置为null。

语法

Animation.cancel();

参数

无.

返回值

无.

异常

这个方法不会直接抛出异常; 但是,如果动画的 {{domxref("Animation.playState", "playState")}} 取消时是除了“空闲”之外的任何东西,{{domxref("Animation.finished", "current finished promise", "", 1)}} 被拒绝与一个 {{domxref("DOMException")}} 命名的AbortError.

规范

Specification Status Comment
{{SpecName('Web Animations', '#dom-animation-cancel', 'Animation.cancel()' )}} {{Spec2('Web Animations')}} Editor's draft.

浏览器兼容

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support {{CompatChrome(39.0)}} {{CompatGeckoDesktop(48)}}[1] {{CompatNo}} {{CompatNo}} {{CompatNo}}
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{CompatVersionUnknown}} {{CompatGeckoMobile(48)}}[1] {{CompatNo}} {{CompatNo}} {{CompatNo}}

[1] The Web Animations API is only enabled by default in Firefox Developer Edition and Nightly builds. You can enable it in beta and release builds by setting the preference dom.animations-api.core.enabled to true, and can disable it in any Firefox version by setting this preference to false.

相关内容