IntersectionObserverEntry: isIntersecting プロパティ
Baseline
広く利用可能
この機能は広く実装されており、多くのバージョンの端末やブラウザーで動作します。2019年3月以降、すべてのブラウザーで利用可能です。
isIntersecting は IntersectionObserverEntry インターフェイスの読み取り専用のプロパティで、対象要素が交差オブザーバーのルートと交差している場合に true になる論理値です。
この値が true の場合、 IntersectionObserverEntry は交差状態への変わり目にあります。 false の場合、交差ありから交差なしへの変わり目であることがわかります。
値
論理値で、 target 要素が交差状態に遷移したか (true) または交差状態から脱したか (false) を示します。
例
この単純な例では、交差コールバックを使用して、現在いくつの対象となる要素が交差ルートと交差しているかのカウンターを更新します。
js
function intersectionCallback(entries) {
entries.forEach((entry) => {
if (entry.isIntersecting) {
intersectingCount += 1;
} else {
intersectingCount -= 1;
}
});
}
より具体的な例については、交差状態の変化の扱いをご覧ください。
仕様書
| 仕様書 |
|---|
| Intersection Observer> # dom-intersectionobserverentry-isintersecting> |