Skip to content

Function: getScrollPercentage() ​

ts
function getScrollPercentage(target?): number;

Calculates the scroll progress percentage for an element or the window.

Parameters ​

ParameterTypeDefault valueDescription
targetHTMLElement | WindowwindowThe scroll container. Defaults to window.

Returns ​

number

The scroll percentage between 0 and 100.

Example ​

ts
getScrollPercentage(document.documentElement)
// => 45

Since ​

1.0.0

Released under the MIT License.