IntersectionObserverEntry:isIntersecting 属性

Baseline 已广泛支持

此功能已成熟,并可在多种设备和浏览器版本上运行。自 2019 年 3 月以来,它已在所有浏览器中可用。

IntersectionObserverEntry 接口的 isIntersecting 只读属性是一个布尔值,如果目标元素与 Intersection Observer 的根(root)相交,则为 true

如果该属性为 true,则 IntersectionObserverEntry 描述了进入相交状态的过渡;如果为 false,则表示从相交状态过渡到不相交状态。

一个布尔值,指示 target 元素是否已过渡到相交状态 (true) 或从相交状态过渡出去 (false)。

示例

在这个简单的例子中,一个相交回调被用来更新当前与 intersection root 相交的目标元素的计数器。

js
function intersectionCallback(entries) {
  entries.forEach((entry) => {
    if (entry.isIntersecting) {
      intersectingCount += 1;
    } else {
      intersectingCount -= 1;
    }
  });
}

要查看更具体的示例,请参阅 处理相交变化。

规范

规范
交集观察器
# dom-intersectionobserverentry-isintersecting

浏览器兼容性