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
lab/elastic-cursorHover 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-cursorOr by URL: https://asafefe.dev/r/lab-elastic-cursor.json
Brings along
- motion
- utils
- @soultel/use-reduced-motion-safe
Usage
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
| Prop | Type | Default | Description |
|---|---|---|---|
| size | number | 20 | Dot diameter in px. |
| color | string | "var(--primary)" | Dot color. |
| hoverScale | number | 2.8 | Scale over a target. |
| stretch | number | 0.7 | Stretch at full speed. 0 keeps it round. |
| targets | string | "a, button, [data-cursor-target]" | Selector for elements that make it swell. |
| hideCursor | boolean | true | Hide the system cursor on mouse and trackpad. |
| blendMode | CSSProperties["mixBlendMode"] | - | Blend mode for the dot, e.g. "multiply". |
