SVGSVGElement: setCurrentTime() 方法
SVGSVGElement 介面的 setCurrentTime() 方法用於調整此 SVG 文件片段的時鐘,從而建立一個新的當前時間。
如果在文件時間線開始之前呼叫 setCurrentTime()(例如,在文件的 SVGLoad 事件觸發之前,由 <script> 元素中執行的指令碼呼叫),那麼該方法最後一次呼叫的秒值將是文件在時間線開始後將跳轉到的時間。
語法
js
setCurrentTime(time)
引數
時間-
一個浮點數,表示要設定的當前時間的秒數。
返回值
無。
示例
設定當前時間
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="setTimeButton">Set Current Time</button>
<p id="currentTimeDisplay"></p>
js
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`;
});
規範
| 規範 |
|---|
| SVG 動畫級別 2 # __svg__SVGSVGElement__setCurrentTime |
瀏覽器相容性
載入中…