This feature is not Baseline because it does not work in some of the most widely-used browsers.
The beginEvent event of the SVGAnimationElement interface is fired when the element local timeline begins to play. It will be raised each time the element begins the active duration (i.e., when it restarts, but not when it repeats).
It may be raised both in the course of normal (i.e., scheduled or interactive) timeline play, as well as in the case that the element was begun with a DOM method.
This event is not cancelable and does not bubble.
Use the event name in methods like addEventListener(), or set an event handler property.
addEventListener("beginEvent", (event) => { })
onbegin = (event) => { }
A TimeEvent. Inherits from Event.
TimeEvent.detail Read only
A long that specifies some detail information about the Event, depending on the type of the event. For this event type, indicates the repeat number for the animation.
TimeEvent.view Read only
A WindowProxy that identifies the Window from which the event was generated.
<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);
});
Note that you can also create an event listener for the begin event using the onbegin event handler property:
animateElem.onbegin = () => {
console.log("beginEvent fired");
};
| Specification |
|---|
| Scalable Vector Graphics (SVG) 2> # BeginEvent> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
beginEvent_event |
3531–35Theonbegin event handler property is not supported. |
79 | 936–93Theonbegin event handler property is not supported. |
2218–22Theonbegin event handler property is not supported. |
10Theonbegin event handler property is not supported. |
3531–35Theonbegin event handler property is not supported. |
936–93Theonbegin event handler property is not supported. |
2218–22Theonbegin event handler property is not supported. |
10Theonbegin event handler property is not supported. |
3.02.0–3.0Theonbegin event handler property is not supported. |
374.4.3–37Theonbegin event handler property is not supported. |
10Theonbegin event handler property is not supported. |
endEvent eventrepeatEvent event
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/SVGAnimationElement/beginEvent_event