Skip to content

QuizNot attempted

IntersectionObserver in a scroll container

Your infinite list scrolls inside a <div style="overflow:auto">, but the observer on the sentinel never fires. Why?
1–4 to choose, Enter to submit
Show answer & explanation

Correct answer:

  • With no root, the observer watches the viewport; pass the scrolling div as root
  • With no root, the observer measures against the viewport, not your scroll container, so rootMargin (and thresholds) are relative to the wrong box
  • pass the scrolling div as root (and add rootMargin to 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.