Animation:cancel() 方法
Web Animations API 的 cancel() 方法,屬於 Animation 介面,用於清除此動畫引起的所有 KeyframeEffect,並中止其播放。
注意: 當動畫被取消時,其 startTime 和 currentTime 會被設定為 null。
語法
js
cancel()
引數
無。
返回值
無(undefined)。
異常
此方法不會直接丟擲異常;但是,如果在取消時動畫的 playState 不是 "idle",則當前的完成 promise 會被一個名為 AbortError 的 DOMException 拒絕。
規範
| 規範 |
|---|
| Web 動畫 # dom-animation-cancel |
瀏覽器相容性
載入中…
另見
- Web Animations API
KeyframeEffectAnimationAnimation.playStateAnimation.finished返回一個 promise,如果動畫的playState不是"idle",該 promise 將被拒絕。