JavaScript · Middle · Question 45 of 75
What's the most convenient way to detect that an element entered the viewport?
- ✓Correct answer: With
IntersectionObserver - 2With
getBoundingClientRect()in ascrollhandler on every pixel - 3With a
MutationObserverwatching the element's attributes
Explanation
IntersectionObserver asynchronously reports when an element intersects the viewport, without loading the main thread on every scroll. Uses: lazy loading, infinite feeds, impression analytics. MutationObserver tracks DOM changes, not visibility.