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

SVGAnimationElement: getStartTime() method

· 52CE 我爱测

The SVGAnimationElement method `getStartTime()` returns a float representing the start time, in seconds, for this animation element's current interval, if it exists, regardless of whether the interval has begun yet.

SVG

The SVGAnimationElement method getStartTime() returns a float representing the start time, in seconds, for this animation element's current interval, if it exists, regardless of whether the interval has begun yet.

The start time returned by getStartTime() is measured in seconds relative to the time container's time zero.

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.

This property reflects the begin attribute of the animate, animateMotion or animateTransform element.

Syntax

getStartTime()

Parameters

None (undefined).

Return value

A float.

Exceptions

  • InvalidStateError DOMException
    • : Thrown if the SVGAnimationElement has no current interval. This happens when the animation element's begin time has not been reached or defined, thus the getStartTime() method cannot determine a valid start time. An example can be when the animation is set to start at begin="click", but the user has not yet clicked to trigger it.

Examples

This example demonstrates how begin="3s" attribute makes the animation start 3 seconds after the time container's timeline begins.

<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="5s" begin="3s" />
  </circle>
</svg>
const animationElement = document.querySelector("animate");

const startTime = animationElement.getStartTime();
console.log(
  `The animation starts at: ${startTime} seconds relative to the time container's timeline`,
); // Output: 3

The getStartTime() method returns 3.0 because that is the time relative to the time container's time zero.

Specifications

Browser compatibility

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

资料来源与适用范围

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

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

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