Class Scrollbar

A custom scrollbar component. Supports both window and HTMLElement containers.

Documentation

Hierarchy (View Summary)

Constructors

  • Parameters

    Returns Scrollbar

Accessors

  • get axis(): "x" | "y"

    Scroll axis

    Returns "x" | "y"

  • get container(): Window | HTMLElement | Snap

    The element to which the scrollbar is applied.

    Returns Window | HTMLElement | Snap

  • get isDestroyed(): boolean

    Checks if the module has been destroyed.

    Returns boolean

  • get name(): string

    The name of the module, derived from the class name

    Returns string

  • get outer(): HTMLElement

    Scrollbar outer element

    Returns HTMLElement

  • get parent(): HTMLElement

    The element where the scrollbar is appended. If parent is not set, it defaults to container or document.body (if applied to window).

    Returns HTMLElement

  • get prefix(): string

    Optional prefix for classnames used by the module

    Returns string

  • get scrollableSize(): number

    Returns the total scrollable distance.

    Returns number

  • get scrollElement(): HTMLElement | Snap

    The actual scrollable element. Returns document.documentElement for window, otherwise the container itself.

    Returns HTMLElement | Snap

  • get scrollSize(): number

    Returns the total scroll width/height of the content.

    Returns number

  • get scrollValue(): number

    Returns scrollTop or scrollLeft of the scrollable element.

    Returns number

  • get thumb(): HTMLElement

    Scrollbar thumb element (draggable handle).

    Returns HTMLElement

  • get thumbSize(): number

    Returns the current thumb size.

    Returns number

  • get track(): HTMLElement

    Scrollbar track element (the container of the thumb).

    Returns HTMLElement

  • get trackSize(): number

    Returns the current track size.

    Returns number

Methods

  • Adds a class name on an element, and keeps track of it for removal when the module is destroyed.

    Parameters

    • element: Element

      The target DOM element.

    • className: string

      The class name to toggle.

    Returns void

  • Helper function to generate classnames with the module's prefix.

    Parameters

    • ...classNames: string[]

      The class names to generate.

    Returns string

    A string of class names with the module's prefix applied.

  • Destroys the component and cleans up resources.

    Returns void

  • Get default mutable properties

    Returns { __mutableProp: true; autoSize: boolean; minSize: string | number }

    • __mutableProp: true
    • autoSize: boolean

      Enables automatic adjustment of the scrollbar size.

      true
      
    • minSize: string | number

      Minimum size of the scrollbar thumb. Accepts numeric values (interpreted as pixels) or CSS units (px, rem, vw, vh, svh).

      50
      
  • Get default static properties

    Returns {
        __staticProp: true;
        autoHide: boolean;
        axis: "x" | "y";
        class: string | false;
        container: Window | HTMLElement | Snap;
        draggable: boolean;
        parent: false | HTMLElement;
        resizeDebounce: number;
    }

    • __staticProp: true
    • autoHide: boolean

      Automatically hides the scrollbar when inactive.

      true
      
    • axis: "x" | "y"

      Defines the scrolling axis for the scrollbar.

      • 'x' for horizontal scrolling.
      • 'y' for vertical scrolling.
      'y'
      
    • class: string | false

      Custom CSS class to be applied to the scrollbar track. If false, no additional class is applied.

      false
      
    • container: Window | HTMLElement | Snap

      The element to which the scrollbar is applied. Can be either the window or a specific HTML element.

      window
      
    • draggable: boolean

      Determines whether the scrollbar thumb is draggable.

      true
      
    • parent: false | HTMLElement

      The parent element where the scrollbar should be appended. If false, the scrollbar is appended directly to the container. For proper behavior, use parent when applying the scrollbar to an HTML element.

      false
      
    • resizeDebounce: number

      Debounce time (in milliseconds) for handling resize events. Helps improve performance by limiting the frequency of resize calculations.

      50
      
  • Destroys the module, cleaning up resources, callbacks, and event listeners.

    Returns void

  • Adds a callback on the module's destruction.

    Parameters

    • action: () => void

      The function to execute during destruction.

    Returns void

  • Resize the scrollbar.

    Returns void