Animation:cancel() 方法

Baseline 已廣泛支援

此功能已經成熟,並可在許多裝置和瀏覽器版本上使用。自 ⁨2020 年 3 月⁩起,它已在各瀏覽器中推出。

Web Animations APIcancel() 方法,屬於 Animation 介面,用於清除此動畫引起的所有 KeyframeEffect,並中止其播放。

注意: 當動畫被取消時,其 startTimecurrentTime 會被設定為 null

語法

js
cancel()

引數

無。

返回值

無(undefined)。

異常

此方法不會直接丟擲異常;但是,如果在取消時動畫的 playState 不是 "idle",則當前的完成 promise 會被一個名為 AbortErrorDOMException 拒絕。

規範

規範
Web 動畫
# dom-animation-cancel

瀏覽器相容性

另見