-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
Overview
This article talks about the application of Intersection Observer API and its compatibility consideration.
The basic API
const options = {
root: document.querySelector("#scrollArea"),
rootMargin: "0px",
threshold: 1.0,
};
let observer = new IntersectionObserver(callback, options);- The threshold: A threshold of 1.0 means that when 100% of the target is visible within the element specified by the root option, the callback is invoked.
- The callback:
let callback = (entries, observer) => {
entries.forEach((entry) => {
// Each entry describes an intersection change for one observed
// target element:
// entry.boundingClientRect
// entry.intersectionRatio
// entry.intersectionRect
// entry.isIntersecting
// entry.rootBounds
// entry.target
// entry.time
});
};