clampTarget

Commons
stable

Clamps a scroll target value to the valid scroll range of a container element, supporting both vertical and horizontal axes. Used internally by the goTo scroll utility.

API

Signature

Signature TypeScript complète, extraite du fichier util.

typescript

API

Paramètres

Paramètres d'entrée acceptés par cet util.

container
requis
HTMLElement
The scrollable container whose scroll range is used as bounds.
value
requis
number
The desired scroll position in pixels.
horizontal
requis
boolean
When true, clamps against the horizontal scroll range; otherwise the vertical range.

API

Valeur de retour

La valeur retournée par cet util.

The clamped scroll position between 0 and the maximum scrollable distance of the container.

Usage

Exemples

Extraits de code prêts à coller.

Prevent over-scrolling

typescript