重啟
示例
html
<svg viewBox="0 0 220 200" xmlns="http://www.w3.org/2000/svg">
<rect y="30" width="100" height="100">
<animate
attributeType="XML"
attributeName="y"
from="30"
to="100"
dur="5s"
repeatCount="1"
restart="always" />
</rect>
<rect x="120" y="30" width="100" height="100">
<animate
attributeType="XML"
attributeName="y"
from="30"
to="100"
dur="5s"
repeatCount="1"
restart="whenNotActive" />
</rect>
<a id="restart"><text y="20">Restart animation</text></a>
</svg>
js
document.getElementById("restart").addEventListener("click", (evt) => {
document.querySelectorAll("animate").forEach((element) => {
element.beginElement();
});
});
使用說明
| 值 | always | whenNotActive | never |
|---|---|
| 預設值 | always |
| 可動畫 | 否 |
always-
此值表示動畫可以隨時重新開始。
whenNotActive-
此值表示僅當動畫未處於活動狀態(即在活動結束之後)時才能重新開始。在動畫的活動持續時間內嘗試重新開始動畫將被忽略。
never-
此值表示動畫無法重新開始。
規範
| 規範 |
|---|
| SVG 動畫級別 2 # RestartAttribute |