Class Cursor

Custom cursor with smooth motion, hover sizing, sticky elements, and typed variants.

  • Builds outer/inner DOM (optional) and hides the native cursor when configured
  • Interpolates position/size via Raf; optional SVG path trailing (behavior: 'path')
  • Hover targets via attachHover; alternate visuals via attachCursor

Documentation

Hierarchy (View Summary)

Constructors

Accessors

  • get container(): Element | Window

    Returns Element | Window

  • get coords(): {
        angle: number;
        height: number;
        velocity: number;
        width: number;
        x: number;
        y: number;
    }

    Smoothed coordinates including width/height.

    Returns {
        angle: number;
        height: number;
        velocity: number;
        width: number;
        x: number;
        y: number;
    }

  • get domContainer(): HTMLElement

    DOM parent for the cursor node (body when container is window).

    Returns HTMLElement

  • get initialHeight(): number

    Returns number

  • get initialWidth(): number

    Returns number

  • get inner(): HTMLElement

    Returns HTMLElement

  • get isDestroyed(): boolean

    Indicates whether the instance has been destroyed.

    After destruction, destroy is a no-op.

    Returns boolean

  • get name(): string

    The name of the module, derived from the class name

    Returns string

  • get outer(): HTMLElement

    Returns HTMLElement

  • get path(): SVGPathElement

    SVG path element for path behavior (not necessarily mounted).

    Returns SVGPathElement

  • get prefix(): string

    Optional prefix for classnames used by the module

    Returns string

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;
        autoStop: boolean;
        enabled: boolean;
        height: string | number;
        lerp: number;
        width: string | number;
    }

    • __mutableProp: true
    • autoStop: boolean

      Stops rendering the cursor automatically when its coordinates and size closely match the target values.

      true
      
    • enabled: boolean

      Enables or disables the custom cursor interactions.

      true
      
    • height: string | number

      The initial height of the custom cursor. Supports css units like px, rem, vw, vh, svh.

      50
      
    • lerp: number

      Linear interpolation factor for smooth cursor movement. The value must be between 0 and 1, with higher values indicating faster movement.

      0.2
      
    • width: string | number

      The initial width of the custom cursor. Supports css units like px, rem, vw, vh, svh.

      50
      
  • Get default static props

    Returns {
        __staticProp: true;
        append: boolean;
        behavior: "path" | "default";
        container: Element | Window;
        hideNative: boolean;
        transformModifier: (coords: ICursorFullCoords) => string;
    }

    • __staticProp: true
    • append: boolean

      Appends the custom cursor to the container. Use false if you need only cursor logic and interactions.

      true
      
    • behavior: "path" | "default"

      Cursor behavior

      'default'
      
    • container: Element | Window

      The container where the custom cursor is active. Use window for full-window activation.

      window
      
    • hideNative: boolean

      Hides the native cursor if set to true.

      false
      
    • transformModifier: (coords: ICursorFullCoords) => string

      Modifier for the cursor transform.

      (coords) => translate(${coords.x}px, ${coords.y}px)

  • Method that is called when the module's properties mutate. In most cases, used to handle callbacks.

    Parameters

    Returns void

  • Registers a typed cursor element and appends it to inner.

    Parameters

    Returns void

  • Registers a hover target that can resize, snap, or sticky-move the cursor.

    Parameters

    Returns () => void

    Destructor that detaches listeners for this target

  • 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

  • Advances interpolation and writes transforms.

    Returns void