Class Marquee<CallbacksMap, StaticProps, MutableProps>

A custom marquee component that smoothly scrolls its child elements.

This component is designed to loop elements horizontally within a container, with support for customization such as speed, gap, pause on hover, and more.

Documentation

Type Parameters

Hierarchy (View Summary)

Constructors

Properties

_callbacks: Callbacks<CallbacksMap>

Callbacks instance

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

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

_elements: HTMLElement[] = []

Array of marquee element nodes

_initialNodes: ChildNode[] = []

Initial child nodes of the container

_intersection?: IntersectionObserver

Intersection observer

_isDestroyed: boolean = false

Tracks whether the module has been destroyed

_lastSetup?: () => void

Last setup handler for teardown

_props: TTRequiredProps<MutableProps & StaticProps>

Current properties

_raf: Raf

Raf instance

_totalWidth: number = 0

Total width of all elements in the marquee

_width: number = 0

Current container width

_widths: number[] = []

Array of widths of each child element

_x: number = 0

The current X coordinate of the marquee.

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 prefix(): string

    Optional prefix for classnames used by the module

    Returns string

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

  • Adds necessary styles to a given element.

    Parameters

    • element: HTMLElement
    • isAbsolute: boolean

    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.

  • Handle intersection observer

    Parameters

    • entries: IntersectionObserverEntry[]

    Returns void

  • Renders the marquee, calculating element positions based on the provided speed.

    Parameters

    • step: string | number = ...

    Returns void

  • Adds a callback on the module's destruction.

    Parameters

    • action: () => void

      The function to execute during destruction.

    Returns void