Skip to content

getScrollPosition()

getScrollPosition(): object

Defined in: src/utils/domUtils.ts:19

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.