SVGSVGElement:pauseAnimations() 方法

Baseline 已广泛支持

此特性已相当成熟,可在许多设备和浏览器版本上使用。自 ⁨2015 年 7 月⁩以来,各浏览器均已提供此特性。

SVGSVGElement 接口的 pauseAnimations() 方法会暂停(即停止)与此 <svg> 元素对应的 SVG 文档片段中定义的所有当前正在运行的动画,导致此文档片段的动画时钟停止,直到再次被取消暂停。

语法

js
pauseAnimations()

参数

无。

返回值

无(undefined)。

示例

暂停动画

html
<svg id="exampleSVG" width="200" height="100">
  <circle cx="50" cy="50" r="30" fill="blue">
    <animate
      attributeName="cx"
      from="50"
      to="150"
      dur="2s"
      repeatCount="indefinite" />
  </circle>
</svg>

<button id="pauseBtn">Pause Animations</button>
<pre id="status"></pre>
js
const svgElement = document.getElementById("exampleSVG");
const pauseButton = document.getElementById("pauseBtn");
const statusDisplay = document.getElementById("status");

pauseButton.addEventListener("click", () => {
  svgElement.pauseAnimations();
  statusDisplay.textContent = "Animations paused.";
});

规范

规范
SVG 动画级别 2
# __svg__SVGSVGElement__pauseAnimations

浏览器兼容性

另见