useScrollPosition
The vertical scroll offset of the page or a scroll container.
Follows window scrolling, or the element in targetRef, with a passive listener. 0 during server rendering.
Usage
Examples
Reading progress in a scroll container
Page scroll
API
1 option
1 return value
Accessibility
A back-to-top control revealed by scrolling should stay in the tab order (hidden with inert or visibility, not just opacity) and move focus sensibly.
Notes
- Updates on every scroll event; throttle derived work with useThrottleCallback.
Related
useThrottleCallbackA function that runs at most once per interval.useCollapsibleSectionsExpanded state for several sections, with expand all and collapse all.useElementSizeAn element's size, kept current with a ResizeObserver.useInViewWhether an element is in the viewport, from an IntersectionObserver.