IntersectionObserverEntry: thuộc tính isIntersecting
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2019.
Thuộc tính chỉ đọc isIntersecting của giao diện IntersectionObserverEntry là một giá trị Boolean cho biết true nếu phần tử đích giao nhau với root của intersection observer.
Nếu là true, IntersectionObserverEntry mô tả một chuyển đổi vào trạng thái giao nhau; nếu là false, bạn biết rằng nó đã chuyển từ giao nhau sang không giao nhau.
Giá trị
Một giá trị Boolean cho biết target đã chuyển vào trạng thái giao nhau (true) hay ra khỏi trạng thái giao nhau (false).
Ví dụ
Trong ví dụ đơn giản này, callback giao nhau được dùng để cập nhật bộ đếm số phần tử đích hiện đang giao nhau với intersection root.
function intersectionCallback(entries) {
entries.forEach((entry) => {
if (entry.isIntersecting) {
intersectingCount += 1;
} else {
intersectingCount -= 1;
}
});
}
Để xem ví dụ cụ thể hơn, hãy xem Handling intersection changes.
Thông số kỹ thuật
| Thông số kỹ thuật |
|---|
| Intersection Observer> # dom-intersectionobserverentry-isintersecting> |