大网数据广告活动
Web 标准与前端开发

AnimationTimeline: currentTime property

· 52CE 我爱测

The **`currentTime`** read-only property of the Web Animations API's AnimationTimeline interface returns the timeline's current time in milliseconds, or `null` if the timeline is inactive.

Web Animations

The currentTime read-only property of the Web Animations API's AnimationTimeline interface returns the timeline's current time in milliseconds, or null if the timeline is inactive.

Value

A number representing the timeline's current time in milliseconds, or null if the timeline is inactive.

Reduced time precision

To offer protection against timing attacks and fingerprinting, the precision of animationTimeline.currentTime may be reduced depending on browser settings.

The current time normally advances with animation frames. Reading the property repeatedly while a script runs does not provide a continuously updating clock.

For a DocumentTimeline, the current time is calculated by subtracting the DocumentTimeline.DocumentTimeline offset, which can be supplied by script, from the browser's animation clock.

In Chrome, the rounding interval for the animation clock during rendering updates is 0.1 ms, or 0.005 ms in cross-origin-isolated contexts. The browser does not apply additional timer rounding after subtracting originTime.

In Safari, the rounding interval for the animation clock is 1 ms, or 0.02 ms in cross-origin-isolated contexts. After subtracting originTime, the browser rounds the returned value to 0.001 ms, the resolution used to represent animation times.

In Firefox, after subtracting originTime, the browser rounds the returned value to 0.02 ms by default, including in cross-origin-isolated contexts. If privacy.resistFingerprinting is enabled, the rounding interval is 16.667 ms or the interval configured by privacy.resistFingerprinting.reduceTimerPrecision.microseconds, whichever is larger.

For example, these are possible values in Firefox:

// Reduced time precision (0.02 ms) with default settings
animationTimeline.currentTime;
// Might be:
// 23.4
// 24.18
// 25.5
// …

// Reduced time precision with `privacy.resistFingerprinting` enabled
animationTimeline.currentTime;
// Might be:
// 50.001
// 66.668
// 83.335
// …

Specifications

Browser compatibility

See also

  • Web Animations API
  • AnimationTimeline
  • DocumentTimeline inherits this property
  • Document.timeline returns a timeline object which inherits this property

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。