ContentVisibilityAutoStateChangeEvent:skipped 属性

Baseline 2024

Newly available

Since September 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

若用户代理跳过元素内容,则 ContentVisibilityAutoStateChangeEvent 接口的只读属性 skipped 返回 true,否则返回 false

布尔值。若用户代理跳过元素内容则返回 true,否则返回 false

示例

js
const canvasElem = document.querySelector("canvas");

canvasElem.addEventListener("contentvisibilityautostatechange", stateChanged);
canvasElem.style.contentVisibility = "auto";

function stateChanged(event) {
  if (event.skipped) {
    stopCanvasUpdates(canvasElem);
  } else {
    startCanvasUpdates(canvasElem);
  }
}

// 在画布需要开始更新时调用此方法。
function startCanvasUpdates(canvas) {
  // …
}

// 在画布需要停止更新时调用此方法。
function stopCanvasUpdates(canvas) {
  // …
}

规范

Specification
CSS Containment Module Level 2
# dom-contentvisibilityautostatechangeevent-skipped

浏览器兼容性

BCD tables only load in the browser

参见