Back

Drag with constraintsAn tutorial of making an element draggable using Motion for React's drag prop. You can even set drag constraints by providing a ref to another element.

tutorialUpdated May 19, 2026

Creating the Project

Let's start the project by creating a Next.js application. We can do that by running npx create-next-app@latest client inside of a terminal.

Creating the 3 slides

Here I'll create 3 slides with a certain left position to randomize the layout.

  • I initialize a Lenis scroll to have a smooth scroll

  • I use an overflow:hidden on the parent to remove the horizontal scroll created by the long slides.

The slides all contain 3 phrases inside of them:

We should have something like this:

Are you ready for impact? 🚀

Let’s connect! Whether you’re looking to collaborate, discuss ideas, or just have a friendly chat, I’d love to hear from you!