Loading...
Loading...
Build gesture-driven web interfaces that feel native: drags, flicks, sheets, swipe-back, swipe actions, pull to refresh, scrubbers, card-to-detail morphs and app-switcher style gestures. Use when adding or fixing anything the user drags, flicks or swipes, when an animation needs to start from the finger's speed, when something should rubber band at an edge, or when a gesture feels stuck, jumpy or janky on touch.
npx skill4agent add rndrealm/fluid-interactions fluid-interactionspackage.jsonnpm install motion # package-lock.json
pnpm add motion # pnpm-lock.yaml
yarn add motion # yarn.lock
bun add motion # bun.lock / bun.lockbmotion/reactmotionanimateuseMotionValueuseTransformMotionConfiguseReducedMotionframer-motionframer-motionelasticbackspringFromResponseVelocityTrackervelocitystop()onCompleteproject(velocity)applyRubberBand(value, min, max, d)xyscaleopacitygetBoundingClientRectclientWidthpointeruppointercancellostpointercapturephysics.tsuse-motion-preference.tsspringFromResponsenoBounceVelocityTrackerrubberBandapplyRubberBandrubberBandInverseprojectDECELERATIONnearestnearestPointclampFADEonEnd{ reduceMotion, spring }spring()const x = useMotionValue(0);
const origin = useRef(0);
const drag = useDrag({
onStart: () => {
x.stop(); // catch it mid-flight
origin.current = x.get(); // continue from where it is on screen
},
onMove: (delta) => {
x.set(applyRubberBand(origin.current + delta.x, min, max, width));
},
onEnd: (velocity) => {
const landing = x.get() + project(velocity.x);
animate(x, nearest(landing, targets), {
...spring(SNAP),
velocity: velocity.x,
});
},
});
return (
<motion.div {...drag} style={{ x }} className="touch-none select-none" />
);| Building | Read |
|---|---|
| Any spring, picking response and damping | springs |
| Draggable or flickable element, snapping to corners or points, custom scroller with momentum and paging | drag and momentum |
| Horizontal swipe inside a vertical list, swipe actions, pull to refresh | direction lock |
| Bottom sheet with detents | sheets |
| Video or audio scrubber with fine scrubbing | scrubbing |
| Thumbnail that grows into a detail view and drags back down to close | morphing |
| Edge swipe to go back in a navigation stack | swipe back |
| One gesture with several outcomes or modes (home bar, fine scrubbing, stretching swipe actions) | gesture modes |
| Reduced motion | reduced motion |
| A gesture that freezes, gets stuck, or breaks taps on touch | pointer events |
| Thing | Value |
|---|---|
| Most UI springs | |
| Navigation, paging, anything that shouldn't overshoot | damping ratio |
| Velocity window | last 100ms |
| Direction lock threshold | 10px |
| Lock ratio for a strict axis | the winning axis is 2× the other |
| Rubber band constant | |
| Projection deceleration | |
| Edge-swipe zone | 24px from the edge |
| Reduced-motion fade | 200ms ease-out |
touch-action