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

SVGAnimationElement: repeatEvent event

· 52CE 我爱测

The **`repeatEvent`** event of the SVGAnimationElement interface is fired when the element's local timeline repeats. It will be fired each time the element repeats, after the first iteration.

SVG

The repeatEvent event of the SVGAnimationElement interface is fired when the element's local timeline repeats. It will be fired each time the element repeats, after the first iteration.

[!NOTE] Associated with the repeatEvent event is an integer that indicates which repeat iteration is beginning; this can be found in the detail property of the event object. The value is a 0-based integer, but the repeat event is not raised for the first iteration and so the observed values will be >= 1. This is supported in Firefox, but not in Chrome.

This event is not cancelable and does not bubble.

Syntax

Use the event name in EventTarget/addEventListener:

addEventListener("repeatEvent", (event) => { })

Alternatively, assign to the event handler property of the interface:

onrepeat = (event) => { }

Event type

A TimeEvent. Inherits from Event.

TimeEvent

Examples

Animated circle

<svg xmlns="http://www.w3.org/2000/svg" width="300px" height="100px">
  <title>SVG SMIL Animate with Path</title>
  <circle cx="0" cy="50" r="50" fill="blue" stroke="black" stroke-width="1">
    <animateMotion path="M 0 0 H 300 Z" dur="5s" repeatCount="indefinite" />
  </circle>
</svg>

<hr />

<ul></ul>
ul {
  height: 100px;
  border: 1px solid #dddddd;
  overflow-y: scroll;
  padding: 10px 30px;
}
let svgElem = document.querySelector("svg");
let animateElem = document.querySelector("animateMotion");
let list = document.querySelector("ul");

animateElem.addEventListener("beginEvent", () => {
  let listItem = document.createElement("li");
  listItem.textContent = "beginEvent fired";
  list.appendChild(listItem);
});

animateElem.addEventListener("repeatEvent", (e) => {
  let listItem = document.createElement("li");
  let msg = "repeatEvent fired";
  if (e.detail) {
    msg += `; repeat number: ${e.detail}`;
  }
  listItem.textContent = msg;
  list.appendChild(listItem);
});

Animated_circle

Using the event handler property

You can also create an event listener for the repeat event using the onrepeat event handler property (but note that this replaces other event listeners added using onrepeat, if any):

animateElem.onrepeat = () => {
  console.log("repeatEvent fired");
};

Specifications

Browser compatibility

See also

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

资料来源与适用范围

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

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

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