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

SVGAnimationElement: getCurrentTime() method

· 52CE 我爱测

The SVGAnimationElement method `getCurrentTime()` returns a float representing the current time in seconds relative to time zero for the given time container.

SVG

The SVGAnimationElement method getCurrentTime() returns a float representing the current time in seconds relative to time zero for the given time container.

Time zero refers to the moment when the time container begins its timeline. It acts as the starting reference point for all animations within that container.

A time container is an element or context that defines a local timeline for one or more animations. Animations inside the time container are measured relative to its timeline. If a time container is delayed, paused, or manipulated, all animations within it adjust accordingly.

Syntax

getCurrentTime()

Parameters

None (undefined).

Return value

A float.

Examples

This example demonstrates how the getCurrentTime() method retrieves the time elapsed since the time container's time zero.

<svg width="200" height="200" viewBox="0 0 200 200">
  <circle cx="50" cy="50" r="20" fill="rebeccapurple">
    <animate
      attributeName="cx"
      from="50"
      to="150"
      dur="4s"
      repeatCount="indefinite" />
  </circle>
</svg>
const animationElement = document.querySelector("animate");

setInterval(() => {
  const currentTime = animationElement.getCurrentTime();
  console.log(
    `Current time relative to the time container: ${currentTime} seconds`,
  );
}, 1000);

The animation starts at time zero = 0 and runs indefinitely, and the getCurrentTime() value increments continuously within the context of the time container.

Specifications

Browser compatibility

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

资料来源与适用范围

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

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

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