useScroll ​
Get the scroll position of an element.
Code demonstration ​
Basic Usage ​
Detect Whole Page Scroll ​
Control listen on scroll status ​
API ​
typescript
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>> |