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. The component then terminates and disconnects its observer, so the event never fires again.
js
onInViewOnceInView() {
// the element entered the viewport for the first time
}Options
intersectionObserver
- Type:
object - Default:
{ threshold: [0, 1] }
Options forwarded to the underlying IntersectionObserver instance created by the withMountWhenInView decorator. Use it to adjust the rootMargin, threshold or root used to detect the viewport crossing.
html
<div data-component="InViewOnce" data-option-intersection-observer='{ "rootMargin": "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.