It enables you to detect the visibility of an element asynchronously.
And also detect the relative visibility of two elements in relationship to each other.
const options = {
root: null,
rootMargin: '10px',
threshold: 1.0
}
const onIntersection = (entries) => {
...
};
const observer = new IntersectionObserver(onIntersection, options);
observer.observe(document.querySelector('#some-target'));
rootMargin
threshold