Drag & Reorder
Sortable Grid
3x3 grid of colored numbered tiles that spring-animate into position as tiles are dragged or swapped; initial idle shuffle stops after first input.
cssmedium complexitymoderate motionpointermobile-ready
Open on the canvas to copy the code → Free account · 3 copies a day · membership goes unlimited
1
When to use it
Dashboard card reordering, settings panels, any UI where users need to manually sort a fixed set of items with tactile feedback.
When not to
Lists longer than ~12 items (spring loop scales linearly); contexts where ordering state must persist — this resets on page reload.
Working with an AI agent
Every component ships agent-ready metadata. An example instruction for this one:
Change the grid to 4 columns (set COLS=4, N=16, add 7 more PAL entries), increase spring stiffness by changing K from 0.14 to 0.22. Theme: dark tokens live in :root, the light variant in :root[data-theme="light"]; ?theme=light or a {type:'forever:theme'} postMessage switches at runtime.
Safe to edit
- palette colors (PAL array)
- grid size (N and COLS)
- spring stiffness (K=0.14) and damping (D=0.74)
- tile corner radius (border-radius:7px)
- idle demo cadence while demoEnabled; first deliberate input disables it permanently
- demo swap interval (1300ms)
- theme tokens (:root dark defaults + [data-theme=light] overrides)
Keep intact
- IIFE wrapper
- visibilitychange stop/start guard
- prefers-reduced-motion early return
- pointer capture (setPointerCapture)
- theme hook (?theme= bootstrap + forever:theme message listener + theme tokens)
- demo-v1 preview lifecycle: initialize demoEnabled from window.__foreverPreview and stop attract work on the window forever:interactive event; retain manual feedback, settling, cleanup and explicit sessions
Known limitations
- Order is not persisted — resets on reload; wire localStorage or a backend to save state
- Manual springs finish settling; requestAnimationFrame sleeps once stable.
- Keyboard mode focuses the grid container, not individual tiles — screen-reader UX is minimal
- State remains local to each mounted instance; format/theme remount preserves takeover, not component values.
More Drag & Reorder components
- Kanban MoveThree-column kanban board where a cyan card lifts and spring-animates between lanes via FLIP. Idle demo stops after first input; supports arrow keys and…
- Pull to RefreshA 5-row canvas list springs down on drag, revealing diagonal bars and a rotating geometric indicator; releasing past threshold triggers a 1.5s sync spinner.
- Dual RangeCanvas dual-range slider with two spring-driven thumbs (white lo, amber hi), hatched fill, delta readout, and tick marks. Initial breathing stops after…
- Carousel ThrowSeven colored cards orbit a glowing hub in a radial ring; drag to fling with angular inertia, release to snap to the nearest card under the marker.
- Drag Handle5 dark rows with grip handles spring-animate to new positions when dragged or arrow-keyed; the lifted row glows cyan and scales up slightly.
- Spring Physics StackPriority queue you reorder by dragging: the lifted row tilts with pointer velocity and neighbours spring into place.