asafefe.dev
Lab

Lab/08

Elastic Cursor

The dot trails your pointer on a spring, stretching along its direction of travel and swelling when it meets a target.

  • Motion
  • Physics
Move inside the field
Hover meAnd meMove fast

Installation

Add Elastic Cursor to your project with the shadcn CLI. The files land in components/lab, ready to edit.

$ pnpm dlx shadcn@latest add @soultel/lab-elastic-cursor

Or by URL: https://asafefe.dev/r/lab-elastic-cursor.json

Brings along

  • motion
  • utils
  • @soultel/use-reduced-motion-safe

Usage

example.tsx10 lines
import { ElasticCursor } from "@/components/lab/elastic-cursor"

export function Example() {
  return (
    <ElasticCursor className="flex h-80 items-center justify-center gap-4">
      <button>Hover me</button>
      <span data-cursor-target>And me</span>
    </ElasticCursor>
  )
}

Props

PropTypeDefaultDescription
sizenumber20Dot diameter in px.
colorstring"var(--primary)"Dot color.
hoverScalenumber2.8Scale over a target.
stretchnumber0.7Stretch at full speed. 0 keeps it round.
targetsstring"a, button, [data-cursor-target]"Selector for elements that make it swell.
hideCursorbooleantrueHide the system cursor on mouse and trackpad.
blendModeCSSProperties["mixBlendMode"]-Blend mode for the dot, e.g. "multiply".