重新開始
restart 屬性指定動畫是否可以重新開始。
你可以將此屬性與以下 SVG 元素一起使用
示例
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 |