IntersectionObserverEntry: thuộc tính target

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 target của giao diện IntersectionObserverEntry cho biết Element đích nào đã thay đổi mức giao nhau với intersection root.

Giá trị

Thuộc tính target của IntersectionObserverEntry chỉ ra Element nào, trước đó được theo dõi bằng cách gọi IntersectionObserver.observe(), đã trải qua thay đổi về mức giao nhau với root.

Ví dụ

Trong ví dụ đơn giản này, opacity của mỗi phần tử đích được đặt bằng intersectionRatio của nó.

js
function intersectionCallback(entries) {
  entries.forEach((entry) => {
    entry.target.style.opacity = entry.intersectionRatio;
  });
}

Để xem ví dụ cụ thể hơn, hãy xem Handling intersection changes.

Thông số kỹ thuật

Specification
Intersection Observer
# dom-intersectionobserverentry-target

Tương thích trình duyệt