開始
begin 屬性定義動畫何時開始。
屬性值是一個用分號分隔的值列表。開始時間列表的解釋在 SMIL 規範的“開始和結束時間列表的評估”中詳細說明。每個單獨的值可以是以下之一:<offset-value>、<syncbase-value>、<event-value>、<repeat-value>、<accessKey-value>、<wallclock-sync-value> 或關鍵字 indefinite。
您可以將此屬性與以下 SVG 元素一起使用
animate、animateMotion、animateTransform、set
對於 <animate>、<animateMotion>、<animateTransform> 和 <set>,begin 定義元素應何時開始,即何時變為活動狀態。
| 值 | <begin-value-list> |
|---|---|
| 預設值 | 0s |
| 可動畫 | 否 |
<begin-value-list> 是一個用分號分隔的值列表。每個值可以是以下之一
<offset-value>-
此值定義了一個時鐘值,表示相對於 SVG 文件開頭的時間點(通常是
load或DOMContentLoaded事件)。負值有效。 <syncbase-value>-
此值定義了一個同步基準以及一個可選的與該同步基準的偏移量。元素的動畫開始時間相對於另一個動畫的開始或活動結束時間定義。
有效的 syncbase-value 包括對另一個動畫元素的 ID 引用,後跟一個點,以及
begin或end以標識是與引用的動畫元素的開始還是活動結束同步。可以附加一個可選的偏移值,如<offset-value>中所定義。 <event-value>-
此值定義了一個事件和一個可選的偏移量,該偏移量確定元素的動畫應開始的時間。動畫開始時間相對於指定事件觸發的時間定義。
有效的 event-value 包括元素 ID,後跟一個點和該元素支援的事件之一。所有有效事件(並非所有元素都支援)由 DOM 和 HTML 規範定義。它們是
focusblurfocusinfocusoutDOMActivateauxclickclickdblclickmousedownmouseentermouseleavemousemovemouseoutmouseovermouseupwheelbeforeinputinputkeydownkeyupcompositionstartcompositionupdatecompositionendloadunloadaborterrorselectresizescrollbeginEventendEventrepeatEvent
可以附加一個可選的偏移值,如
<offset-value>中所定義。 <repeat-value>-
此值定義了一個限定的重複事件。元素動畫開始時間相對於具有指定迭代值的重複事件引發的時間定義。
有效的 repeat 值包括元素 ID,後跟一個點和函式
repeat(),該函式的引數是指定重複次數的整數。可以附加一個可選的偏移值,如<offset-value>中所定義。 <accessKey-value>-
此值定義了一個應觸發動畫的訪問鍵。當用戶按下指定的鍵時,元素動畫將開始。
有效的 accessKey-value 包括函式
accessKey(),其引數是要輸入的字元。可以附加一個可選的偏移值,如<offset-value>中所定義。 <wallclock-sync-value>-
此值將動畫開始時間定義為現實世界中的時鐘時間。
有效的 wallclock-sync-value 包括函式
wallclock(),其引數是時間值。時間語法基於ISO 8601中定義的語法。 indefinite-
動畫的開始將由
beginElement()方法呼叫或目標為該元素的超連結確定。
示例
偏移量示例
<svg
width="120"
height="120"
viewBox="0 0 120 120"
xmlns="http://www.w3.org/2000/svg"
version="1.1">
<!-- animated rectangles -->
<rect x="10" y="35" height="15" width="0">
<animate
attributeType="XML"
attributeName="width"
to="100"
begin="0s"
dur="8s"
fill="freeze" />
</rect>
<rect x="35" y="60" height="15" width="0">
<animate
attributeType="XML"
attributeName="width"
to="75"
begin="2s"
dur="6s"
fill="freeze" />
</rect>
<rect x="60" y="85" height="15" width="0">
<animate
attributeType="XML"
attributeName="width"
to="50"
begin="4s"
dur="4s"
fill="freeze" />
</rect>
<!-- grid -->
<text x="10" y="20" text-anchor="middle">0s</text>
<line x1="10" y1="25" x2="10" y2="105" stroke="grey" stroke-width=".5" />
<text x="35" y="20" text-anchor="middle">2s</text>
<line x1="35" y1="25" x2="35" y2="105" stroke="grey" stroke-width=".5" />
<text x="60" y="20" text-anchor="middle">4s</text>
<line x1="60" y1="25" x2="60" y2="105" stroke="grey" stroke-width=".5" />
<text x="85" y="20" text-anchor="middle">6s</text>
<line x1="85" y1="25" x2="85" y2="105" stroke="grey" stroke-width=".5" />
<text x="110" y="20" text-anchor="middle">8s</text>
<line x1="110" y1="25" x2="110" y2="105" stroke="grey" stroke-width=".5" />
<line x1="10" y1="30" x2="110" y2="30" stroke="grey" stroke-width=".5" />
<line x1="10" y1="105" x2="110" y2="105" stroke="grey" stroke-width=".5" />
</svg>
同步基準示例
<svg
width="120"
height="120"
viewBox="0 0 120 120"
xmlns="http://www.w3.org/2000/svg"
version="1.1"
xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- animated rectangles -->
<rect x="10" y="35" height="15" width="0">
<animate
attributeType="XML"
attributeName="width"
to="50"
id="first"
begin="0s;third.end"
dur="4s" />
</rect>
<rect x="60" y="60" height="15" width="0">
<animate
attributeType="XML"
attributeName="width"
to="25"
id="second"
begin="first.end"
dur="2s" />
</rect>
<rect x="85" y="85" height="15" width="0">
<animate
attributeType="XML"
attributeName="width"
to="25"
id="third"
begin="second.end"
dur="2s" />
</rect>
<!-- grid -->
<text x="10" y="20" text-anchor="middle">0s</text>
<line x1="10" y1="25" x2="10" y2="105" stroke="grey" stroke-width=".5" />
<text x="35" y="20" text-anchor="middle">2s</text>
<line x1="35" y1="25" x2="35" y2="105" stroke="grey" stroke-width=".5" />
<text x="60" y="20" text-anchor="middle">4s</text>
<line x1="60" y1="25" x2="60" y2="105" stroke="grey" stroke-width=".5" />
<text x="85" y="20" text-anchor="middle">6s</text>
<line x1="85" y1="25" x2="85" y2="105" stroke="grey" stroke-width=".5" />
<text x="110" y="20" text-anchor="middle">8s</text>
<line x1="110" y1="25" x2="110" y2="105" stroke="grey" stroke-width=".5" />
<line x1="10" y1="30" x2="110" y2="30" stroke="grey" stroke-width=".5" />
<line x1="10" y1="105" x2="110" y2="105" stroke="grey" stroke-width=".5" />
</svg>
事件示例
<svg
width="120"
height="120"
viewBox="0 0 120 120"
xmlns="http://www.w3.org/2000/svg"
version="1.1"
xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- animated rectangle -->
<rect x="10" y="35" height="15" width="0">
<animate
attributeType="XML"
attributeName="width"
from="0"
to="100"
begin="startButton.click"
dur="8s"
fill="freeze" />
</rect>
<!-- trigger -->
<rect
id="startButton"
style="cursor:pointer;"
x="19.5"
y="62.5"
rx="5"
height="25"
width="80"
fill="#EFEFEF"
stroke="black"
stroke-width="1" />
<text x="60" y="80" text-anchor="middle" style="pointer-events:none;">
Click me.
</text>
<!-- grid -->
<text x="10" y="20" text-anchor="middle">0s</text>
<line x1="10" y1="25" x2="10" y2="55" stroke="grey" stroke-width=".5" />
<text x="35" y="20" text-anchor="middle">2s</text>
<line x1="35" y1="25" x2="35" y2="55" stroke="grey" stroke-width=".5" />
<text x="60" y="20" text-anchor="middle">4s</text>
<line x1="60" y1="25" x2="60" y2="55" stroke="grey" stroke-width=".5" />
<text x="85" y="20" text-anchor="middle">6s</text>
<line x1="85" y1="25" x2="85" y2="55" stroke="grey" stroke-width=".5" />
<text x="110" y="20" text-anchor="middle">8s</text>
<line x1="110" y1="25" x2="110" y2="55" stroke="grey" stroke-width=".5" />
<line x1="10" y1="30" x2="110" y2="30" stroke="grey" stroke-width=".5" />
<line x1="10" y1="55" x2="110" y2="55" stroke="grey" stroke-width=".5" />
</svg>
重複示例
<svg
width="120"
height="120"
viewBox="0 0 120 120"
xmlns="http://www.w3.org/2000/svg"
version="1.1"
xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- animated rectangle -->
<rect x="10" y="35" height="15" width="0">
<animate
attributeType="XML"
attributeName="width"
from="0"
to="100"
id="myLoop"
begin="0s;myLoop.end"
dur="4s"
repeatCount="3" />
<set
attributeType="CSS"
attributeName="fill"
to="green"
begin="myLoop.begin" />
<set
attributeType="CSS"
attributeName="fill"
to="gold"
begin="myLoop.repeat(1)" />
<set
attributeType="CSS"
attributeName="fill"
to="red"
begin="myLoop.repeat(2)" />
</rect>
<!-- grid -->
<text x="10" y="20" text-anchor="middle">0s</text>
<line x1="10" y1="25" x2="10" y2="55" stroke="grey" stroke-width=".5" />
<text x="35" y="20" text-anchor="middle">1s</text>
<line x1="35" y1="25" x2="35" y2="55" stroke="grey" stroke-width=".5" />
<text x="60" y="20" text-anchor="middle">2s</text>
<line x1="60" y1="25" x2="60" y2="55" stroke="grey" stroke-width=".5" />
<text x="85" y="20" text-anchor="middle">3s</text>
<line x1="85" y1="25" x2="85" y2="55" stroke="grey" stroke-width=".5" />
<text x="110" y="20" text-anchor="middle">4s</text>
<line x1="110" y1="25" x2="110" y2="55" stroke="grey" stroke-width=".5" />
<line x1="10" y1="30" x2="110" y2="30" stroke="grey" stroke-width=".5" />
<line x1="10" y1="55" x2="110" y2="55" stroke="grey" stroke-width=".5" />
</svg>
訪問鍵示例
<svg
width="120"
height="120"
viewBox="0 0 120 120"
xmlns="http://www.w3.org/2000/svg"
version="1.1"
xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- animated rectangles -->
<rect x="10" y="35" height="15" width="0">
<animate
attributeType="XML"
attributeName="width"
from="0"
to="100"
begin="accessKey(s)"
dur="8s"
fill="freeze" />
</rect>
<!-- trigger -->
<text x="60" y="80" text-anchor="middle" style="pointer-events:none;">
Hit the "s" key
</text>
<!-- grid -->
<text x="10" y="20" text-anchor="middle">0s</text>
<line x1="10" y1="25" x2="10" y2="55" stroke="grey" stroke-width=".5" />
<text x="35" y="20" text-anchor="middle">2s</text>
<line x1="35" y1="25" x2="35" y2="55" stroke="grey" stroke-width=".5" />
<text x="60" y="20" text-anchor="middle">4s</text>
<line x1="60" y1="25" x2="60" y2="55" stroke="grey" stroke-width=".5" />
<text x="85" y="20" text-anchor="middle">6s</text>
<line x1="85" y1="25" x2="85" y2="55" stroke="grey" stroke-width=".5" />
<text x="110" y="20" text-anchor="middle">8s</text>
<line x1="110" y1="25" x2="110" y2="55" stroke="grey" stroke-width=".5" />
<line x1="10" y1="30" x2="110" y2="30" stroke="grey" stroke-width=".5" />
<line x1="10" y1="55" x2="110" y2="55" stroke="grey" stroke-width=".5" />
</svg>
此示例嵌入在 iframe 中。如果要啟用鍵事件,則必須先單擊它。
規範
| 規範 |
|---|
| SVG 動畫級別 2 # BeginAttribute |