Created
September 23, 2025 07:31
-
-
Save mattgperry/779db51d2bac3881656696c8df812dfe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| Simplified version of https://examples.motion.dev/react/card-stack | |
| **/ | |
| import { motion, useMotionValue, useTransform, animate } from "framer-motion" | |
| function SwipeableCard() { | |
| const x = useMotionValue(0) | |
| const rotate = useTransform(x, [-200, 200], [-25, 25]) | |
| const onDragEnd = (event, info) => { | |
| // If swiped far enough or fast enough, animate it off-screen | |
| if (Math.abs(info.offset.x) > 100 || Math.abs(info.velocity.x) > 500) { | |
| const direction = info.offset.x > 0 ? 1 : -1 | |
| animate(x, direction * 500, { | |
| type: "spring", | |
| stiffness: 400, | |
| damping: 40, | |
| }) | |
| // Here you would trigger logic to show the next card | |
| } else { | |
| // Otherwise, animate it back to the center | |
| animate(x, 0, { type: "spring", stiffness: 600, damping: 30 }) | |
| } | |
| } | |
| return ( | |
| <motion.div | |
| drag="x" | |
| style={{ x, rotate }} | |
| onDragEnd={onDragEnd} | |
| dragConstraints={{ left: 0, right: 0, top: 0, bottom: 0 }} | |
| // Add your card styling here | |
| /> | |
| ) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment