Drag & physics

Draggable

Grab it, throw it. Momentum carries it, the walls bounce it back with rubber-band resistance, snap points catch it.

Paste it into ChatGPT, Claude, Cursor or v0.
axis
elastic0.35
throw power1.0
rotate on drag6
rubber stretch0.40

Usage

import { Draggable } from '@vizzele/react';

<div className="arena">
  <Draggable bounds="parent" elastic={0.35} rotate={6} stretch={0.4} className="card">
    Throw me
  </Draggable>
</div>

Props

PropTypeDefaultDescription
axis'x' | 'y' | 'both''both'Restrict movement to one axis.
lockDirectionbooleanfalseLock to the axis the gesture starts on.
bounds'parent' | HTMLElement | Partial<Bounds>—Keep it inside an element or px limits.
elasticnumber0.35Rubber-band resistance past bounds (0 = hard wall).
momentumbooleantrueKeep gliding after release.
powernumber1Throw distance multiplier.
timeConstantnumber0.4Glide duration (s).
snap{ x?, y?, points? }—Snap values per axis or 2D points.
returnToOriginbooleanfalseSpring back on release.
handlestring | HTMLElement—Only drag from this child.
rotatenumber0Tilt (deg) with horizontal speed.
stretchnumber0Rubber stretch along the velocity (0–1).
keyboardnumber | false16Arrow-key step in px.
springSpringConfig | SpringPreset'liquid'Spring for snapping, bouncing and returning.
onStart / onMove / onEnd / onRest(state: DragState) => void—Lifecycle. Return false from onEnd to drive the release yourself.

Accessibility

  • Focusable; arrow keys move it (Shift for bigger steps), snapping to the next point when snap points exist.
  • Mouse, touch and pen through Pointer Events. Single-axis drags let the page scroll on the other axis.
  • Reduced motion: no throwing — it stays where you drop it (clamped to bounds).