IntersectionObserverEntry:isIntersecting 屬性
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 |
瀏覽器相容性
載入中…