AnimationPlaybackEvent: currentTime 屬性

Baseline 已廣泛支援

此特性已經十分成熟,可在許多裝置和瀏覽器版本上使用。自 2020 年 7 月以來,它已在各大瀏覽器中可用。

currentTimeAnimationPlaybackEvent 介面的一個只讀屬性,表示生成此事件時動畫的當前時間。如果動畫在生成事件時處於 idle 狀態,此值將為未解析(unresolved)。

一個數字,表示當前時間(以毫秒為單位),或者 null

時間精度降低

為了防止計時攻擊和指紋識別playbackEvent.currentTime 的精度可能會根據瀏覽器設定而進行舍入。在 Firefox 中,privacy.reduceTimerPrecision 首選項預設啟用,並預設為 2ms。你也可以啟用 privacy.resistFingerprinting,在這種情況下,精度將是 100ms 或 privacy.resistFingerprinting.reduceTimerPrecision.microseconds 的值,取兩者中較大的一個。

例如,在降低時間精度的情況下,playbackEvent.currentTime 的結果將始終是 0.002 的倍數;如果啟用了 privacy.resistFingerprinting,則為 0.1(或 privacy.resistFingerprinting.reduceTimerPrecision.microseconds)的倍數。

js
// reduced time precision (2ms) in Firefox 60
playbackEvent.currentTime;
// Might be:
// 23.404
// 24.192
// 25.514
// …

// reduced time precision with `privacy.resistFingerprinting` enabled
playbackEvent.currentTime;
// Might be:
// 49.8
// 50.6
// 51.7
// …

規範

規範
Web 動畫
# dom-animationplaybackevent-currenttime

瀏覽器相容性

另見