Firefox Tomorrow

web api instance method

SVGSVGElement: setCurrentTime() method

View on MDN ↗

The setCurrentTime() method of the SVGSVGElement interface adjusts the clock for this SVG document fragment, establishing a new current time.

If setCurrentTime() is called before the document timeline has begun (for example, by script running in a <script> element before the document’s SVGLoad event is dispatched), then the value of seconds in the last invocation of the method gives the time that the document will seek to once the document timeline has begun.

Syntax

setCurrentTime(time)

Parameters

  • time
    • : A float representing the time in seconds to set the current time.

Return value

None.

Examples

Setting the Current Time

<svg
  id="exampleSVG"
  width="200"
  height="200"
  xmlns="http://www.w3.org/2000/svg">
  <circle id="circle1" cx="100" cy="100" r="50" fill="blue" />
</svg>
<button id="setTimeButton">Set Current Time</button>
<p id="currentTimeDisplay"></p>
const svgElement = document.getElementById("exampleSVG");
const setTimeButton = document.getElementById("setTimeButton");
const currentTimeDisplay = document.getElementById("currentTimeDisplay");

setTimeButton.addEventListener("click", () => {
  // Setting the time to 5 seconds
  svgElement.setCurrentTime(5);
  const currentTime = svgElement.getCurrentTime();
  currentTimeDisplay.textContent = `Current time in the SVG: ${currentTime} seconds`;
});

Specifications

SpecificationsStandards references are available on the canonical MDN page.

Browser compatibility

Browser compatibilityCompatibility data is available on the canonical MDN page.