SVGSVGElement: getCurrentTime()-Methode
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.
Die getCurrentTime()
-Methode des SVGSVGElement
-Interfaces gibt die aktuelle Zeit in Sekunden relativ zur Startzeit des aktuellen SVG-Dokumentfragments zurück.
Wenn getCurrentTime()
aufgerufen wird, bevor die Dokument-Timeline begonnen hat (beispielsweise durch ein Skript, das in einem <script>
-Element ausgeführt wird, bevor das SVGLoad
-Ereignis des Dokuments ausgelöst wird), wird 0
zurückgegeben.
Syntax
js
getCurrentTime()
Parameter
Keine.
Rückgabewert
Ein Float.
Beispiele
Abrufen der aktuellen Zeit
html
<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="getTimeButton">Get Current Time</button>
<p id="currentTimeDisplay"></p>
js
const svgElement = document.getElementById("exampleSVG");
const getTimeButton = document.getElementById("getTimeButton");
const currentTimeDisplay = document.getElementById("currentTimeDisplay");
getTimeButton.addEventListener("click", () => {
const currentTime = svgElement.getCurrentTime();
currentTimeDisplay.textContent = `Current time in the SVG: ${currentTime} seconds`;
});
Spezifikationen
Specification |
---|
SVG Animations Level 2 # __svg__SVGSVGElement__getCurrentTime |
Browser-Kompatibilität
BCD tables only load in the browser