Skip to content

getScrollPosition() ​

getScrollPosition(): object

Defined in: utils/dom/getScrollPosition.ts:15

Retrieves the current scroll position of the window.

This function calculates the horizontal (x) and vertical (y) scroll positions using window.scrollX, window.scrollY, or fallback methods for older browsers.

Returns ​

object

An object containing the x and y scroll positions.

x ​

x: number

y ​

y: number

Example ​

tsx
const { x, y } = getScrollPosition();
console.log(`Scroll X: ${x}, Scroll Y: ${y}`);

Released under the MIT License.