IsInViewport
Track if an element is visible within the current viewport.
IsInViewport
uses the useIntersectionObserver
utility to track if an element is visible within the current viewport.
It accepts an element or getter that returns an element and an optional options
object that aligns
with the useIntersectionObserver
utility options.
Demo
Target node
Scroll down to observe the behavior
Target node is
viewportUsage
Basic Usage
One-time Detection
The once
option automatically stops observing after the first intersection. This is useful for
one-time animations or loading content when it becomes visible:
Observer Controls
The IsInViewport
class provides methods to control the underlying intersection observer. See useIntersectionObserver
for more information.