QuizNot attempted
IntersectionObserver in a scroll container
1–4 to choose, Enter to submit
Show answer & explanation
Correct answer:
- With no
root, the observer watches the viewport; pass the scrolling div asroot
- With no
root, the observer measures against the viewport, not your scroll container, sorootMargin(and thresholds) are relative to the wrong box - pass the scrolling div as
root(and addrootMarginto load early). - Not images only: it observes any element.
- Not threshold must be 1: the default 0 fires on the first visible pixel
- 1 makes it harder to trigger.
- Not 'React-added elements': observers work on any DOM node once
observe()is called. - Observers beat
onScroll+getBoundingClientRect: async, no forced layout.