Class ScrollProgress

Tracks scroll progress of a section relative to the viewport or a scroll root.

  • Emits update on scroll (and optionally only while the section is visible)
  • Exposes inProgress, outProgress, moveProgress, and progress
  • Supports a custom scroll container via root and optional useSvh height

Documentation

Hierarchy (View Summary)

  • Module<TC, TS, TM>
    • ScrollProgress

Constructors

Accessors

  • get inProgress(): { x: number; y: number }

    Progress while the section is entering the root.

    Returns { x: number; y: number }

  • get isDestroyed(): boolean

    Indicates whether the instance has been destroyed.

    After destruction, destroy is a no-op.

    Returns boolean

  • get isVisible(): boolean

    Whether the section is currently considered visible (optimized mode).

    Returns boolean

  • get moveProgress(): { x: number; y: number }

    Progress while the section moves through the root (pin-like range).

    Returns { x: number; y: number }

  • get name(): string

    The name of the module, derived from the class name

    Returns string

  • get outProgress(): { x: number; y: number }

    Progress while the section is leaving the root.

    Returns { x: number; y: number }

  • get prefix(): string

    Optional prefix for classnames used by the module

    Returns string

  • get progress(): { x: number; y: number }

    Full travel progress from entering to fully leaving the root.

    Returns { x: number; y: number }

  • get section(): Element

    Section element whose progress is tracked.

    Returns Element

Methods

  • Adds prefixed classes to an element and removes them on destroy.

    Skips classes that are already present on the element.

    Parameters

    • element: Element

      Target DOM element.

    • ...classes: string[]

      Unprefixed class name segments.

    Returns void

  • Builds one or more prefixed class names.

    Parameters

    • ...classes: string[]

      Unprefixed class name segments.

    Returns string

    Space-separated prefixed class string.

  • Internal method to handle the destruction of the module. It removes all callbacks, destroys properties, and cleans up event listeners and class names.

    Returns void

  • Set default mutable props

    Returns { __mutableProp: true }

  • Get default static props

    Returns {
        __staticProp: true;
        optimized: boolean;
        root: Element;
        section: Element;
        useSvh: boolean;
    }

    • __staticProp: true
    • optimized: boolean

      If true, progress is calculated only while the section is within the viewport or the root element. Improves performance by avoiding unnecessary calculations.

      true
      
    • root: Element

      The root element used as a reference for scroll progress calculation. Usually it is the scroll container. If null, the viewport is used as the reference.

      null
      
    • section: Element

      The element whose scroll progress is tracked.

    • useSvh: boolean

      If true, the scroll progress is calculated based on the small viewport height (svh in css) instead of the current viewport height (vh in css).

      false
      
  • Destroys the instance and runs all registered cleanup actions.

    Safe to call multiple times; subsequent calls are ignored.

    Execution order:

    1. _destroy
    2. all onDestroy callbacks, in registration order
    3. isDestroyed is set to true

    Returns void

  • Progress of the section's top/left corner between the given thresholds.

    Parameters

    • topThreshold: number

      Y start threshold.

    • rightThreshold: number

      X end threshold.

    • bottomThreshold: number

      Y end threshold.

    • leftThreshold: number

      X start threshold.

    Returns { x: number; y: number }

    Progress along x and y.

    const progress = getProgress(0, vevet.width, vevet.height / 2, 0)
    // progress.y is 0 at the start of the root, 1 at the vertical midpoint
  • Registers a function to run when the instance is destroyed.

    If the instance is already destroyed, action runs immediately.

    Parameters

    • action: () => void

      Cleanup function (for example remove listeners or DOM classes).

    Returns void

  • Refreshes root/section bounds and emits update.

    Parameters

    • isForce: boolean = false

      When true, updates even if the section is not visible.

    Returns void