



IntersectionObserver can take an options object with three properties:
const options = {root: null,rootMargin: "0%",threshold: 0,}const observer = new IntersectionObserver(() => {}, options)
Can be set to:
null) orSets the root's intersection area size.
By default, it's 100% of the viewport.
It accepts values similar to the CSS margin property in pixels or percentages.
If set to -50% 0, the area will be a 1px line in the middle of the viewport.
const options = {rootMargin: "0% 0%"}


Sets how much of the target needs to overlap the intersection area to fire the callback.
A value between 0 (0%) and 1 (100%).
A value of 0 will fire the callback when 1px of the target overlaps.
It can also be set to an array. Example: [0.2, 0.4, 0.6, 0.8]
const options = {rootMargin: "-25% 0%",threshold: 0.2}


The callback is executed when:
observer.observe(target) andIt takes two arguments:
entries: a list of IntersectionObserverEntry for each target that reported a change.observer: the observer.const observer = new IntersectionObserver((entries, observer) => {entries.forEach((entry) => {const {boundingClientRect,intersectionRatio,intersectionRect,isIntersecting,rootBounds,target,time} = entry...})})
// to stop observing a targetobserver.unobserve(target)// to stop observing all targetsobserver.disconnect()
The callback is executed on the main thread. This means if the code in the callback requires a lot of system resources, it could degrade UX (User Experience) by blocking the browser. If this is the case, consider using requestIdleCallback.
Have any feedback about this note or just want to comment on the state of the economy?


