Class Scrollbar<CallbacksMap, StaticProps, MutableProps>

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

Documentation

Type Parameters

Hierarchy (View Summary)

Constructors

Properties

_addInActionTimeout?: Timeout

Timeout for scroll action

_callbacks: Callbacks<CallbacksMap>

Callbacks instance

_destroyable: () => void[] = []

Stores actions that need to be executed when the module is destroyed

_isDestroyed: boolean = false

Tracks whether the module has been destroyed

_outer: HTMLElement

Scrollbar outer element.

_prevScrollValue: number = 0

Previous scroll value

_props: TTRequiredProps<MutableProps & StaticProps>

Current properties

_removeInActionTimeout?: Timeout

Timeout for scroll action

_thumb: HTMLElement

Scrollbar thumb element (draggable handle).

_track: HTMLElement

Scrollbar track element (the container of the thumb).

_valueOnSwipeStart: number = 0

Save scroll value on swipe start

Accessors

  • 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 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 scrollElement(): HTMLElement

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

    Returns HTMLElement

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.

  • Adds a callback on the module's destruction.

    Parameters

    • action: () => void

      The function to execute during destruction.

    Returns void