SVGSVGElement: getCurrentTime() 方法
SVGSVGElement 介面的 getCurrentTime() 方法返回當前 SVG 文件片段相對於其開始時間的時間(以秒為單位)。
如果在文件時間線開始之前呼叫 getCurrentTime()(例如,在文件的 SVGLoad 事件觸發之前,在 <script> 元素中執行的指令碼),則返回 0。
語法
js
getCurrentTime()
引數
無。
返回值
浮點數。
示例
獲取當前時間
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`;
});
規範
| 規範 |
|---|
| SVG 動畫級別 2 # __svg__SVGSVGElement__getCurrentTime |
瀏覽器相容性
載入中…