Scroll Progress from Extents

Compute normalized scroll progress from explicit extents; a non-scrollable viewport has defined zero progress.

Description

Compute normalized scroll progress from explicit extents; a non-scrollable viewport has defined zero progress.

Scroll progress is a fraction of maximum scroll distance. Nonoverflowing content needs an explicit zero convention.

When to use this tool

Compute normalized scroll progress from explicit extents; a non-scrollable viewport has defined zero progress.

  • Prepare the supplied scrollPosition, contentExtent, viewportExtent fields for this operation.
  • Compare the complete example with the representation used by your own input before carrying the result into another step.

How to use the tool and how it works

  1. Enter scrollPosition, contentExtent, viewportExtent. Use the exact text syntax, units and index conventions explained below.
  2. Run the tool. If input validation fails, correct the supplied fields before interpreting any result.
  3. Read result.progress, result.maximumScroll. Interpret false, null and empty lists using the distinctions below; they can be valid outputs.

Compute maximumScroll=max(0,contentExtent-viewportExtent), require scrollPosition within it and return position/maximum or zero when maximum is zero.1

Input fieldMeaning and representationAccepted input
scrollPositionscroll position.Finite number
contentExtentcontent extent.Finite number; zero or greater
viewportExtentviewport extent.Finite number; zero or greater
Output fieldInterpretation
resultObject containing the named outputs below.
result.progressThe progress value under the stated formula or text convention.
result.maximumScrollThe maximum scroll value under the stated formula or text convention.
json
{
  "input": {
    "scrollPosition": 25,
    "contentExtent": 200,
    "viewportExtent": 100
  },
  "output": {
    "result": {
      "progress": 0.25,
      "maximumScroll": 100
    }
  }
}

Limitations and assumptions

  • No DOM scroll range, overscroll, reversed axis or RTL convention is inferred.
  • Rectangle arrays use [x,y,width,height] with nonnegative extents. All dimensions must use the same coordinate frame and unit; values are supplied rather than measured from a page.
  • Every declared top-level field is required and unexpected fields are rejected. Numeric inputs must be finite; ordinary text fields are bounded to 8,192 UTF-16 code units, with tighter operation-specific limits where stated.
  • String lists have at most 128 entries of at most 128 code units; matrices have at most 128 rows and columns. Larger numeric lists and parsed JSON have separate bounded budgets. Nonfinite results and excessively large serialized outputs are rejected.
  • Indexes are zero-based and spans have an exclusive end unless explicitly stated otherwise. A valid false, null or empty-list result is distinct from malformed input.

Alternative or Complementary methods

Measure the actual layout when browser behavior matters. The formulas use supplied coordinates and explicit simplifications; they do not account for every box, writing mode, clipping ancestor or simultaneous layout change.

References

  1. Tool behavior and example: Scroll Progress from Extents — tool.io

Similar or alternative tools

  • Scroll Position from Progress

    Invert normalized scroll progress into a position using explicit content/viewport extents.

  • Rectangle Scroll Reveal Delta

    Plan minimum-edge scroll reveal deltas in axis-aligned coordinates, prioritizing the leading edge when an item exceeds viewport size; no DOM scrolling occurs.

Don't forget to set a bookmark for tool.io!
Privacy | Imprint | Cookies