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

Full TypeScript signature sourced from the util file.

typescript

API

Parameters

Input parameters accepted by this util.

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

API

Return value

The value returned by this util.

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

Usage

Examples

Ready-to-paste usage snippets.

Prevent over-scrolling

typescript