Skip to content

Function: getScrollPosition()

ts
function getScrollPosition(el): Position;

Gets the scroll position of the specified target element.

Parameters

ParameterTypeDescription
elTargetTypeThe target element to get the scroll position for.

Returns

Position

A Position object that contains the horizontal and vertical scroll position of the specified target element.

Remarks

This function returns the horizontal and vertical scroll position of the specified target element, which can be an HTML element or the window or document object.

Example

ts
const windowScrollPosition = getScrollPosition(window)
console.log(`Window scroll position: left = ${windowScrollPosition.left}, top = ${windowScrollPosition.top}`)

const documentScrollPosition = getScrollPosition(document)
console.log(`Document scroll position: left = ${documentScrollPosition.left}, top = ${documentScrollPosition.top}`)

Since

1.0.0

Released under the MIT License.