MotionMotionDragGestureInteractive

Draggable Card

Create draggable elements with constraints and spring physics using Motion gestures. Includes rotation based on drag velocity.

Preview

Drag me!

Code

import { motion } from 'motion/react'

export function DraggableCard({ children }) {
  return (
    <motion.div
      drag
      dragConstraints={{ left: -100, right: 100, top: -100, bottom: 100 }}
      dragElastic={0.1}
      whileDrag={{ scale: 1.1, cursor: 'grabbing' }}
      transition={{
        type: 'spring',
        stiffness: 300,
        damping: 20,
      }}
      className="cursor-grab rounded-xl bg-white p-6 shadow-lg"
    >
      {children}
    </motion.div>
  )
}

Want to see more?

Browse the full collection of animation snippets and find your next inspiration.