Cursor Grid
Web (React)
An interactive canvas grid that reacts to cursor proximity and clicks.
A highly optimized <canvas> implementation of a grid that lights up based on cursor proximity and triggers ripples on click. Since it uses requestAnimationFrame and canvas 2D, it has a negligible impact on DOM performance, easily running at 60fps on huge containers.
Hover over the grid
Installation
CLI
npx @modus-ui/cli add cursor-gridManual
- Copy the code from the component tab.
- Create a file at
components/ui/cursor-grid.tsx. - Paste the code.
Usage
tsx
Props
| Prop | Type | Default | Description |
|---|---|---|---|
color | string | "hsl(var(--primary))" | Colour of highlighted cells. |
cellSize | number | 32 | Size of each grid cell in pixels. |
radius | number | 120 | Radius in pixels of the cursor's influence. |
falloff | "linear" | "exponential" | "gaussian" | "gaussian" | How the highlight fades with distance from the cursor. |
holdTime | number | 0 | Milliseconds a cell stays lit before fading. |
fadeDuration | number | 600 | Milliseconds a cell takes to fade out. |
lineWidth | number | 1 | Width of the grid lines in pixels. |
maxOpacity | number | 1 | Maximum opacity of a highlighted cell. |
fillOpacity | number | 0.1 | Opacity of the fill of highlighted cells. |
gridOpacity | number | 0.05 | Opacity of the resting grid lines. |
cellRadius | number | 4 | Corner radius of each cell in pixels. |
clickPulse | boolean | true | Sends a ripple across the grid on click. |
pulseSpeed | number | 800 | Duration in milliseconds of the click ripple. |
Comments