TwitterGitHub
Dark LogoStratik / UIbeta
useScrollbar

The useScrollbar hook provides an easy way to track the scroll position and direction of either the window or a specific element on the page. It can be useful for triggering animations or loading content based on scroll behavior.

Parameters
NameTypeDefaultDescription
elementIdOrRefstring | React.RefObject<HTMLElement>-A string representing the element's ID or a React ref to the target element. Defaults to the window.
Return Values
NameTypeDescription
scrollPosition{ x: number, y: number }An object representing the current scroll position along the x and y axes.
directionXboolean | nulltrue if scrolling right, false if scrolling left, null if no movement detected.
directionYboolean | nulltrue if scrolling down, false if scrolling up, null if no movement detected.

Scrolling Down: False

Scrolling Right: False

Scroll Position X: 0

Scroll Position Y: 0