fn
useWindowScroll
v0.0.14testeddemoReactive 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
| Parameter | Type | Description |
|---|---|---|
options? | UseWindowScrollOptions | Options |
Returns
UseWindowScrollReturnReactive x, y, isScrolling, arrivedState, directions and a measure() helper| Property | Type | Description |
|---|---|---|
x | WritableComputedRef<number> | Reactive horizontal scroll position. Writing to it scrolls the window. |
y | WritableComputedRef<number> | Reactive vertical scroll position. Writing to it scrolls the window. |
isScrolling | ShallowRef<boolean> | Whether the window is currently being scrolled. |
arrivedState | Reactive<UseWindowScrollEdgeState> | Whether each edge of the document has been reached. |
directions | Reactive<UseWindowScrollEdgeState> | The direction(s) the window is currently scrolling towards. |
measure | () => void | Force a re-measurement of arrivedState/directions. |