Skip to main content

Function: useElScrollPosition()

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

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

useElScrollPosition

Parameters

elementRef

RefObject<HTMLElement | null>

Ref to the element to track.

refTrigger

string | number | boolean

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

scrollEl?

HTMLElement | Document

The element to attach the scroll listener to.

Returns

number | undefined

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);