pub struct UseIntersectionObserver {
pub target: NodeRef<Element>,
pub visible: Signal<bool>,
pub ratio: Signal<f64>,
/* private fields */
}Expand description
Reactive state for an element’s visibility.
The handle carries the element the hook watches — a NodeRef the
caller attaches to its own markup — and the signals that report
whether the element is intersecting the viewport and how much of it
is visible.
This is the cheap way to defer the work of an off-screen element: the signal only changes when the element actually crosses the viewport, so a render closure that reads it stays quiet while the element scrolls past.
Fields§
§target: NodeRef<Element>The element the hook watches.
Attach it to the caller’s markup with the ref: attribute.
visible: Signal<bool>Whether the element is currently intersecting the viewport.
ratio: Signal<f64>The fraction of the element that is visible, from 0 to 1.
Implementations§
Source§impl UseIntersectionObserver
Inherent implementation of UseIntersectionObserver.
impl UseIntersectionObserver
Inherent implementation of UseIntersectionObserver.
Sourcepub fn is_visible(&self) -> bool
pub fn is_visible(&self) -> bool
Returns the current visibility as a snapshot.
§Returns
bool-truewhen the element is intersecting the viewport.
Sourcepub fn current_ratio(&self) -> f64
pub fn current_ratio(&self) -> f64
Returns the current visible fraction as a snapshot.
§Returns
f64- The visible fraction, from 0 to 1.