useElementScroll
Tracks a scrollable element's scroll position, active scrolling state, movement directions, and edge arrival flags.
The useElementScroll hook monitors a scrollable element's x and y scroll offsets, active scrolling state, movement directions (left, right, top, bottom), and edge arrival flags (arrived), while providing a programmatic scrollTo helper.
Installation
Usage
Examples
Infinite Scroll Container
Check arrived.bottom together with an offset.bottom threshold to load more items when the user nears the bottom of a list.
Scroll-to-Top Button inside a Container
Use y to show a button after scrolling down and scrollTo to smoothly return to the top.
API Reference
UseElementScrollOptions
Configuration options for scroll tracking, offsets, and scroll behavior.
throttleMs?idleDelayMs?isScrolling resets to falseoffset?UseElementScrollReturn
Scroll coordinates, direction flags, arrival state, and control helpers returned by the hook.
xscrollLeft)yscrollTop)isScrollingdirectionsarrivedscrollToScrollToOptionsxOrOptionsnumber | ScrollToOptionsy?numberScrollDirections
Flags indicating the direction of the most recent scroll movement.
leftrequiredrightrequiredtoprequiredbottomrequiredScrollArrivedState
Flags indicating whether the scroll container has reached any of its edges.
topbottomleftrightScrollOffset
Pixel thresholds from each edge used when computing arrived flags.
top?arrived.top as truebottom?arrived.bottom as trueleft?arrived.left as trueright?arrived.right as true