Class Cursor<CallbacksMap, StaticProps, MutableProps>

A customizable custom cursor component with smooth animations and hover interactions. Supports dynamic appearance changes and enhanced user interaction.

Documentation

Type Parameters

Hierarchy (View Summary)

Constructors

Properties

_activeTypes: string[]

Active cursor types

_callbacks: Callbacks<CallbacksMap>

Callbacks instance

The current coordinates

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

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

_hoveredElement?: ICursorHoveredElement

The currently hovered element

_inner: HTMLElement

The inner element of the custom cursor.

_isDestroyed: boolean = false

Tracks whether the module has been destroyed

_isFirstMove: boolean = true

Defines if the cursor has been moved after initialization

_outer: HTMLElement

The outer element of the custom cursor

_props: TTRequiredProps<MutableProps & StaticProps>

Current properties

_raf: Raf

Request animation frame handler

_targetCoords: ICursorFullCoords

Target coordinates of the cursor (without smooth interpolation).

_types: ICursorType[]

Cursor types

Accessors

  • get inner(): HTMLElement

    The inner element of the custom cursor. This element is nested inside the outer element and can provide additional styling.

    Returns HTMLElement

  • get isDestroyed(): boolean

    Checks if the module has been destroyed.

    Returns boolean

  • get isInterpolated(): boolean

    Checks if all coordinates are interpolated.

    Returns boolean

    True if all coordinates are interpolated, false otherwise.

  • get name(): string

    The name of the module, derived from the class name

    Returns string

  • get outer(): HTMLElement

    The outer element of the custom cursor. This is the visual element that represents the cursor on screen.

    Returns HTMLElement

  • get targetCoords(): { height: number; width: number; x: number; y: number }

    Target coordinates of the cursor (without smooth interpolation).

    Returns { height: number; width: number; x: number; y: 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.

  • 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

  • Performs linear interpolation.

    Parameters

    • current: number

      The current value.

    • target: number

      The target value.

    Returns number

    The interpolated value.

  • Enable or disable a cursor type

    Parameters

    • type: string
    • isEnabled: boolean

    Returns void

  • Registers an element to interact with the cursor, enabling dynamic size and position changes based on hover effects.

    Parameters

    • settings: ICursorHoveredElement

      The settings for the hovered element.

    • OptionalenterTimeout: number = 100

      The timeout before the hover effect is applied.

    Returns () => void

    Returns a destructor

  • Adds a callback on the module's destruction.

    Parameters

    • action: () => void

      The function to execute during destruction.

    Returns void