JS API
The InViewOnce class extends the InView primitive. As it inherits its API, make sure to have a look at its own API reference too. Unlike InView, it emits in-view only once and never emits out-of-view.
Events
in-view
Emitted once, when the element first enters the viewport. InViewOnce declares the visible mount strategy, which mounts and never unmounts, and it suppresses out-of-view, so the event never fires again.
js
onInViewOnceInView() {
// the element entered the viewport for the first time
}Options
InViewOnce declares none. The viewport margin belongs to the mount strategy, so it is written on the data-mount attribute as the strategy's suffix — the value becomes the IntersectionObserver rootMargin:
html
<div data-component="InViewOnce" data-mount="visible:100px">...</div>See also
- The
InViewprimitive is the repeating counterpart: it emitsin-viewandout-of-viewon every viewport crossing. - The
Sentinelprimitive emits a single, non-directionalintersectedevent on both enter and leave.