IntersectionObserver theo dõi khi element đi vào/ra viewport hoặc ancestor element.
- Asynchronous, không block main thread, hiệu quả hơn scroll event listeners.
- Dùng cho: lazy loading images, infinite scroll, animations triggered by scroll, tracking ad visibility.
IntersectionObserver tracks when an element enters or exits the viewport or an ancestor element.
- It is asynchronous, does not block the main thread, and is more efficient than scroll event listeners.
- Used for: lazy loading images, infinite scroll, scroll-triggered animations, and tracking ad visibility.