Miss. Train. Move.

Zero-g card

Product cards, showcases. Weightless: thrown, it floats, spins and drifts home.

Move UI chrome mark
Sport
Gymnastics
Move
Weightless: thrown, it floats, spins and drifts home.
For
Product cards, showcases

drag, throw, arrows nudge · stepped by time · reduced: still

01 Install

Terminal
npx shadcn@latest add https://moveui-red.vercel.app/r/zero-g-card.json

It brings the tokens with it. The first time, import the tokens once in your root layout:

app/layout.tsx
import "@/components/moveui/tokens.css";

Not using shadcn? Copy the files below into components/moveui/, and tokens.css next to them.

02 Use it

Example
import { ZeroGCard } from "@/components/moveui/zero-g-card/zero-g-card";

<ZeroGCard label="Match ball">
  <img src="/ball.png" alt="" width={160} height={160} />
</ZeroGCard>

03 Or ask your agent

Paste this into Claude Code, Cursor or any coding agent. It installs the piece and wires it in.

Prompt
Add the Move UI "Zero-g card" piece to this project. It's for: Product cards, showcases.

1. Install it: npx shadcn@latest add https://moveui-red.vercel.app/r/zero-g-card.json
2. If the project doesn't import the Move UI tokens yet, add this once to the root layout: import "@/components/moveui/tokens.css";
3. Use it like this, adapted to where it belongs in my code:

import { ZeroGCard } from "@/components/moveui/zero-g-card/zero-g-card";

<ZeroGCard label="Match ball">
  <img src="/ball.png" alt="" width={160} height={160} />
</ZeroGCard>

Keep its reduced-motion behaviour and keyboard support. Don't hardcode durations, easing or colours: they come from the --ml-* tokens.
Docs: https://moveui-red.vercel.app/pieces/zero-g-card

Want your agent to know the whole library and its motion rules? Add the Move UI skill to your project:

Terminal
npx shadcn@latest add https://moveui-red.vercel.app/r/skill.json

04 Code

components/moveui/zero-g-card/zero-g-card.tsx
"use client";

import { useEffect, useRef, type ReactNode } from "react";
import "./zero-g-card.css";

/**
 * Zero-g card: whatever you put inside floats as if there were no gravity. Grab it and throw it:
 * it drifts, spins and bounces softly off the card's edges, then slowly settles back to the middle.
 * Arrow keys give it a nudge. A tap (or Enter/Space) calls onTap, for example to show the next item.
 * Physics is stepped by time, so it feels the same at 60Hz and 120Hz. Pauses off screen.
 * Constants come from --ml-zerog-pull / -drag / -bounce. Reduced motion: it stays still.
 */
type Props = { children: ReactNode; label?: string; onTap?: () => void; className?: string };

const num = (el: Element, name: string, fallback: number) => {
  const v = parseFloat(getComputedStyle(el).getPropertyValue(name));
  return Number.isFinite(v) ? v : fallback;
};

export function ZeroGCard({ children, label = "Floating object", onTap, className }: Props) {
  const stageRef = useRef<HTMLDivElement>(null);
  const bodyRef = useRef<HTMLDivElement>(null);
  const tapRef = useRef(onTap);
  useEffect(() => { tapRef.current = onTap; }, [onTap]);

  useEffect(() => {
    const stage = stageRef.current, body = bodyRef.current;
    if (!stage || !body) return;
    const reduce = matchMedia("(prefers-reduced-motion: reduce)").matches;
    const PULL = num(stage, "--ml-zerog-pull", 0.004);
    const DRAG = num(stage, "--ml-zerog-drag", 0.985);
    const BOUNCE = num(stage, "--ml-zerog-bounce", 0.6);

    // Position in px, rotation in degrees, velocities in px (or deg) per 60fps frame.
    const s = { x: 0, y: 0, r: 0, vx: 0, vy: 0, vr: 0 };
    const t0 = performance.now();
    let held = false, raf = 0, last = 0, seen = false;

    const put = () => {
      const now = performance.now();
      const bob = held || reduce ? 0 : Math.sin((now - t0) / 900) * 6;
      const sway = held || reduce ? 0 : Math.sin((now - t0) / 1300) * 1.5;
      body.style.transform = `translate(${s.x.toFixed(1)}px, ${(s.y + bob).toFixed(1)}px) rotate(${(s.r + sway).toFixed(2)}deg)`;
    };
    const step = (t: number) => {
      const f = Math.max(0, Math.min((t - last) / (1000 / 60), 2)); // frames elapsed at 60fps, never negative
      last = t;
      if (!held) {
        // Weak pull to the middle and little drag: it drifts for a while before settling.
        s.vx += -s.x * PULL * f; s.vy += -s.y * PULL * f; s.vr += -s.r * PULL * 1.5 * f;
        s.vx *= DRAG ** f; s.vy *= DRAG ** f; s.vr *= 0.97 ** f;
        s.x += s.vx * f; s.y += s.vy * f; s.r += s.vr * f;
        // Soft walls inside the card, so it never leaves for good.
        const mx = stage.clientWidth * 0.18, my = stage.clientHeight * 0.22;
        if (Math.abs(s.x) > mx) { s.x = Math.sign(s.x) * mx; s.vx *= -BOUNCE; s.vr += s.vx * 0.4; }
        if (Math.abs(s.y) > my) { s.y = Math.sign(s.y) * my; s.vy *= -BOUNCE; s.vr -= s.vy * 0.3; }
      }
      put();
      raf = seen && !document.hidden ? requestAnimationFrame(step) : 0;
    };
    const run = () => {
      if (!raf && seen && !reduce && !document.hidden) { last = performance.now(); raf = requestAnimationFrame(step); }
    };
    const io = new IntersectionObserver(([e]) => { seen = e.isIntersecting; run(); }, { threshold: 0.1 });
    io.observe(stage);
    document.addEventListener("visibilitychange", run);

    // Grab and throw. A press that barely moves is a tap.
    let px = 0, py = 0, sx = 0, sy = 0, lt = 0, moved = false;
    const down = (e: PointerEvent) => {
      if (e.button) return;
      held = true; moved = false;
      sx = px = e.clientX; sy = py = e.clientY; lt = performance.now();
      s.vx = s.vy = 0;
      stage.setPointerCapture(e.pointerId);
      stage.setAttribute("data-held", "");
    };
    const move = (e: PointerEvent) => {
      if (!held) return;
      if (Math.abs(e.clientX - sx) + Math.abs(e.clientY - sy) > 6) moved = true;
      if (reduce) return;
      const dx = e.clientX - px, dy = e.clientY - py, now = performance.now(), dt = Math.max(1, now - lt);
      s.x += dx; s.y += dy; s.r += dx * 0.08;
      // Throw speed from the last stretch of the drag, in px per 60fps frame.
      s.vx = (dx / dt) * 16; s.vy = (dy / dt) * 16; s.vr = s.vx * 0.25;
      px = e.clientX; py = e.clientY; lt = now;
      put();
    };
    const up = () => {
      if (!held) return;
      held = false;
      stage.removeAttribute("data-held");
      if (performance.now() - lt > 80) { s.vx *= 0.2; s.vy *= 0.2; } // held still before letting go
      if (!moved) tapRef.current?.();
      run();
    };
    const key = (e: KeyboardEvent) => {
      const push: Record<string, [number, number]> = { ArrowLeft: [-9, 0], ArrowRight: [9, 0], ArrowUp: [0, -9], ArrowDown: [0, 9] };
      if (push[e.key]) {
        e.preventDefault();
        if (reduce) return;
        s.vx += push[e.key][0]; s.vy += push[e.key][1]; s.vr += push[e.key][0] * 0.3;
        run();
      } else if (e.key === "Enter" || e.key === " ") {
        e.preventDefault();
        tapRef.current?.();
      }
    };
    stage.addEventListener("pointerdown", down);
    stage.addEventListener("pointermove", move);
    stage.addEventListener("pointerup", up);
    stage.addEventListener("pointercancel", up);
    stage.addEventListener("keydown", key);
    return () => {
      cancelAnimationFrame(raf);
      io.disconnect();
      document.removeEventListener("visibilitychange", run);
      stage.removeEventListener("pointerdown", down);
      stage.removeEventListener("pointermove", move);
      stage.removeEventListener("pointerup", up);
      stage.removeEventListener("pointercancel", up);
      stage.removeEventListener("keydown", key);
    };
  }, []);

  return (
    <div
      ref={stageRef}
      className={["ml-zerog", className].filter(Boolean).join(" ")}
      role="group"
      tabIndex={0}
      aria-roledescription="floating card"
      aria-label={`${label}. Drag to throw, arrow keys to nudge${onTap ? ", Enter for the next one" : ""}.`}
    >
      <div ref={bodyRef} className="ml-zerog__body">{children}</div>
    </div>
  );
}
components/moveui/zero-g-card/zero-g-card.css
/*
  Zero-g card. The stage is the card; the body floats inside it. All motion is JS physics
  (pull, drag and bounce from --ml-zerog-* tokens). Reduced motion: the body stays centred.
*/
.ml-zerog {
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}
.ml-zerog[data-held] { cursor: grabbing; }
.ml-zerog:focus-visible { outline: 2px solid var(--ml-focus); outline-offset: -2px; }
.ml-zerog__body { will-change: transform; }
.ml-zerog__body img { display: block; -webkit-user-drag: none; pointer-events: none; }