Intersection Observer API
The Intersection Observer API provides a way to asynchronously observe changes in the intersection of a target element with an ancestor element or viewport.
- Lazy loading images/contents
- Infinite scrolling
- Scroll-driven animations
- Ad visibility tracking
- Task scheduling based on visibility
⚙️ Observer Settings
% of element visibility needed to trigger
Margin around root (like CSS margin)
📊 Scroll Info
Scroll Percentage:
Sticky Header: INACTIVE
🎯 Observable Elements
Scroll to see intersection changesBox 1
Box 2
Box 3
Box 4
Box 5
Box 6
Box 7
Box 8
Box 9
🖼️ Lazy Loading Demo
∞ Infinite Scroll Demo
- Item #1
- Item #2
- Item #3
- Item #4
- Item #5
- Item #6
- Item #7
- Item #8
- Item #9
- Item #10
- Loading more...
📝 Code Example
JavaScript Editor
Use Cases & Best Practices
Common Use Cases:
- Lazy loading images, videos, iframes
- Implementing infinite scroll
- Triggering animations on scroll
- Reporting ad visibility
- Deferring non-critical resources
- Implementing "read more" functionality
Best Practices:
- Use appropriate thresholds for your use case
- Unobserve elements when done
- Disconnect observer when component unmounts
- Consider performance with many observed elements
- Use rootMargin for pre-loading content
- Combine with other APIs (ResizeObserver, etc.)