useScrollPosition()
The
useScrollPosition() hook tracks the global window scroll coordinates in real-time. It is useful for creating reading progress bars, sticky navigation menus, or triggering animations as the user scrolls down the page.Import
typescript
Usage
Scroll the page up and down to see the values update.
Window Scroll Coordinates
0X-Axis (px)
0Y-Axis (px)
Page Progress: 0%
Component.tsx
API
Arguments
This hook does not accept any arguments.
Returns
Returns an object containing the scroll coordinates:
x– number The horizontal scroll amount in pixels (from window.pageXOffset).y– number The vertical scroll amount in pixels (from window.pageYOffset).