end

end 屬性定義了動畫的結束值,可以限制動畫的活動持續時間。

你可以將此屬性與以下 SVG 元素一起使用

用法說明

預設值 None
<end-value-list>
可動畫的

<end-value-list> 是一個以分號分隔的值列表。每個值可以是以下之一:

<offset-value>

此值定義了一個 時鐘值,表示相對於 SVG 文件開始時間的某個時間點(通常是 loadDOMContentLoaded 事件)。負值也是有效的。

<syncbase-value>

此值定義了一個同步基準以及與該同步基準可選的偏移量。元素的動畫結束時間相對於另一個動畫的開始或活動結束時間來定義。

有效的 syncbase-value 由另一個動畫元素的 ID 引用組成,後跟一個點,然後是 beginend,以識別是與引用的動畫元素的開始同步還是與活動結束同步。可以附加 <offset-value> 中定義的可選偏移量。

<event-value>

此值定義了一個事件以及一個可選的偏移量,用於確定元素動畫應結束的時間。動畫結束時間相對於指定事件觸發的時間來定義。

有效的 event-value 由一個元素 ID 組成,後跟一個點,然後是該元素支援的事件之一。所有有效事件(不一定所有元素都支援)均由 DOM 和 HTML 規範定義。它們是:

可以附加 <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

動畫的結束將由 SVGAnimationElement.endElement() 方法呼叫決定。

示例

偏移量示例

html
<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"
      end="8s"
      fill="freeze" />
  </rect>

  <rect x="10" y="60" height="15" width="0">
    <animate
      attributeType="XML"
      attributeName="width"
      to="75"
      begin="0s"
      end="6s"
      fill="freeze" />
  </rect>

  <rect x="10" y="85" height="15" width="0">
    <animate
      attributeType="XML"
      attributeName="width"
      to="50"
      begin="0s"
      end="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>

事件示例

html
<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="0s"
      end="endButton.click"
      dur="8s"
      repeatCount="indefinite"
      fill="freeze" />
  </rect>

  <!-- trigger -->
  <rect
    id="endButton"
    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" 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>

訪問鍵示例

html
<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="0s"
      end="accessKey(e)"
      dur="8s"
      repeatCount="indefinite"
      fill="freeze" />
  </rect>

  <!-- trigger -->
  <text x="60" y="80" text-anchor="middle" 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
# EndAttribute