Advanced

Draggable

Make any HTML element draggable with full physics support — snapping, flicking, throwing, and spring-based release animations.

createDraggable()

import { createDraggable, createSpring } from 'animejs';

createDraggable('.circle', {
  container: '.wrapper',
  releaseEase: createSpring({
    stiffness: 120,
    damping: 8,
    mass: 1,
  }),
  snap: { x: 50, y: 50 },
});

Options

PropertyDefaultDescription
containernullCSS selector or element to constrain dragging within
xtrueAllow horizontal dragging
ytrueAllow vertical dragging
snapnullSnap grid: {x: number, y: number}
releaseEase'outExpo'Easing after release (supports spring)
releaseDuration500Duration of release animation in ms
releaseVelocity1Multiplier for release throw velocity

Callbacks

Spring Physics

import { createSpring } from 'animejs';

const spring = createSpring({
  stiffness: 200, // spring strength
  damping: 10,   // oscillation dampening
  mass: 1,        // simulated mass
  velocity: 0,   // initial velocity
});