SVGSVGElement: phương thức animationsPaused()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

Phương thức animationsPaused() của giao diện SVGSVGElement kiểm tra xem các hoạt hình trong mảnh tài liệu SVG có đang tạm dừng hay không.

Cú pháp

js
animationsPaused()

Tham số

Không có.

Giá trị trả về

Một boolean. true nếu mảnh tài liệu SVG này đang ở trạng thái tạm dừng.

Ví dụ

Kiểm tra xem hoạt hình có đang tạm dừng không

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">Tạm dừng/Tiếp tục hoạt hình</button>
<pre id="status"></pre>
js
const svgElement = document.getElementById("exampleSVG");
const pauseButton = document.getElementById("pauseBtn");
const statusDisplay = document.getElementById("status");

function updateStatus() {
  const isPaused = svgElement.animationsPaused();
  statusDisplay.textContent = `Animations paused: ${isPaused}`;
}

pauseButton.addEventListener("click", () => {
  if (svgElement.animationsPaused()) {
    svgElement.unpauseAnimations();
  } else {
    svgElement.pauseAnimations();
  }
  updateStatus();
});

// Khởi tạo hiển thị trạng thái
updateStatus();

Thông số kỹ thuật

Thông số kỹ thuật
SVG Animations Level 2
# __svg__SVGSVGElement__animationsPaused

Tương thích trình duyệt

Xem thêm