Skip to main content

Function: useElScrollPosition()

useElScrollPosition(elementRef, refTrigger, scrollEl?): undefined | number

Defined in: hooks/useScrollPosition/index.ts:99

useElScrollPosition

Parameters

elementRef

RefObject<null | HTMLElement>

Ref to the element to track.

refTrigger

A trigger to re-run the effect when the ref is set.

string | number | boolean

scrollEl?

The element to attach the scroll listener to.

HTMLElement | Document

Returns

undefined | number

The vertical scroll position of the element.

Description

Tracks the vertical scroll position of an element relative to the viewport.

Example

const myRef = useRef(null);
const [refSet, setRefSet] = useState(false);
const position = useElScrollPosition(myRef, refSet);