Motion's drag function makes elements draggable.
drag(".box")It's the same physics-based gesture as the React drag prop, with:
-
Momentum
-
Axis locking
-
Elastic constraints
-
Direction locking
Browsers provide a native Drag and Drop API. But it's built to move data, not elements, and it comes with an odd "ghost image" effect. drag moves the element itself, with transform, so it stays smooth.
Usage
Import
drag can be imported via "motion".
import { drag } from "motion"Make an element draggable
drag accepts an Element, an array of elements, or a CSS selector. A selector makes every matching element draggable.
drag(document.getElementById("my-id"))
drag(".card")