Class Marquee

Infinite marquee for horizontal or vertical looping content.

  • Wraps text nodes when needed and styles child elements for absolute looping
  • Auto-clones content to avoid visible gaps when cloneNodes is enabled
  • Advances via Raf and supports FPS-adjusted speed
  • Can pause on hover and while outside the viewport

Documentation

Hierarchy (View Summary)

Constructors

Accessors

  • get coord(): number

    The current marquee coordinate.

    Returns number

  • set coord(value: number): void

    Parameters

    • value: number

    Returns void

  • get gap(): number

    Marquee gap

    Returns number

  • get isDestroyed(): boolean

    Indicates whether the instance has been destroyed.

    After destruction, destroy is a no-op.

    Returns boolean

  • get isVertical(): boolean

    Check if the marquee is vertical

    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

  • get totalSize(): number

    Total size of all elements in the marquee (width or height depending on direction)

    Returns number

  • get totalWidth(): number

    Returns number

    Use totalSize instead

  • get x(): number

    Returns number

    Use coord instead

  • set x(value: number): void

    Parameters

    • value: number

    Returns void

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.

  • Stops playback, restores DOM, and removes container styles.

    Returns void

  • Set default mutable props

    Returns {
        __mutableProp: true;
        adjustSpeed: boolean;
        centered: boolean;
        enabled: boolean;
        gap: string | number;
        pauseOnHover: boolean;
        pauseOnOut: boolean;
        speed: string | number;
    }

    • __mutableProp: true
    • adjustSpeed: boolean

      When need to use dynamic FPS factor to adjust the speed of the marquee.

      true
      
    • centered: boolean

      Centers the marquee content within the container.

      false
      
    • enabled: boolean

      Enables or disables the marquee animation. When false, the marquee will be paused.

      true
      
    • gap: string | number

      The gap between the marquee elements. Supports css units like px, rem, vw, vh, svh.

      0
      
    • pauseOnHover: boolean

      Pauses the marquee when the mouse hovers over it.

      false
      
    • pauseOnOut: boolean

      Pauses the marquee when the element leaves the viewport.

      true
      
    • speed: string | number

      The speed of the marquee animation. Supports css units like px, rem, vw, vh, svh.

      1
      
  • Get default static props

    Returns {
        __staticProp: true;
        cloneNodes: boolean;
        container: HTMLElement;
        direction: "horizontal" | "vertical";
        hasWillChange: boolean;
        resizeDebounce: number;
    }

    • __staticProp: true
    • cloneNodes: boolean

      Indicates whether to clone the marquee nodes. Can be set to false if DOM cloning is not preferred.

      true
      
    • container: HTMLElement

      The container element that holds the marquee content.

    • direction: "horizontal" | "vertical"

      Indicates the direction of the marquee animation.

      'horizontal'
      
    • hasWillChange: boolean

      Determines whether to apply the will-change CSS property to the marquee elements to optimize rendering. Setting this to true may improve performance.

      true
      
    • resizeDebounce: number

      The debounce delay for the resize event in milliseconds.

      0
      
  • 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

  • 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

  • Renders the marquee, adjusting element positions.

    Parameters

    • stepProp: string | number = ...

    Returns void

  • Resizes the marquee, recalculating element positions and cloning if necessary.

    Returns void