fn

useWindowScroll

v0.0.14testeddemo

Reactive window scroll position with arrived/direction tracking. Writing to x/y scrolls the window.

Example

ts
const { x, y, isScrolling, arrivedState, directions } = useWindowScroll();

Demo

Loading demo…

Signature

ts
export function useWindowScroll(options: UseWindowScrollOptions ={ ... }

Parameters

ParameterTypeDescription
options?UseWindowScrollOptionsOptions

Returns

UseWindowScrollReturnReactive x, y, isScrolling, arrivedState, directions and a measure() helper
PropertyTypeDescription
xWritableComputedRef<number>Reactive horizontal scroll position. Writing to it scrolls the window.
yWritableComputedRef<number>Reactive vertical scroll position. Writing to it scrolls the window.
isScrollingShallowRef<boolean>Whether the window is currently being scrolled.
arrivedStateReactive<UseWindowScrollEdgeState>Whether each edge of the document has been reached.
directionsReactive<UseWindowScrollEdgeState>The direction(s) the window is currently scrolling towards.
measure() => voidForce a re-measurement of arrivedState/directions.