useScroll
Get the scroll position of an element.
Code demonstration
Basic Usage
Detect Whole Page Scroll
Control listen on scroll status
API
const position = useScroll(target, shouldUpdate)
const position = useScroll(target, shouldUpdate)
Params
Property | Description | Type | Default |
---|---|---|---|
target | DOM element or ref object | Element | Document | (() => Element) | JSX.Element | document |
shouldUpdate | Whether update position | ({ top: number, left: number }) => boolean | - |
Result
Property | Description | Type |
---|---|---|
position | The current scroll position of the element. | Readonly<Ref<{ left: number, top: number } | undefined>> |