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.
API
Parameters
Input parameters accepted by this util.
- containerrequiredHTMLElement
- The scrollable container whose scroll range is used as bounds.
- valuerequirednumber
- The desired scroll position in pixels.
- horizontalrequiredboolean
- 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