Back to Explore
THE PLAYGROUND · GESTURES

Rubber-band / Overscroll

A surface resists being pulled past its boundary.

Rubber-band / OverscrollGestures · A surface resists being pulled past its boundary.
DRAG
Just a little stretch.Always finds its way back.
DRAG TO INTERACT · 600 ms
1import { useState } from "react";2import { motion } from "motion/react";3 4const surface = { width: 100, height: 100, borderRadius: 16, background: "#b8ed79", display: "grid", placeItems: "center", color: "#141714" };5 6export default function RubberBandDemo() {7  const [dismissed, setDismissed] = useState(false);8  const [rotation, setRotation] = useState(0);9  return <div style={{width: 320, overflow: "hidden"}}>10    <button onClick={() => {setDismissed(false); setRotation(0);}}>Reset</button>11    {!dismissed && <motion.div style={surface} drag="true" dragConstraints={{left: 0, right: 0, top: 0, bottom: 0}} dragElastic={0.25} animate={{rotate: rotation}} transition={{ type: "spring", stiffness: 180, damping: 14, mass: 1 }}12      onDrag={(_, info) => undefined}13      onDragEnd={(_, info) => {  }}>Drag me</motion.div>}14    15  </div>;16}

Install: npm install motion. Use elastic drag constraints and spring back on release. This compact example illustrates the core technique; the styled playground contains additional presentation details.