Framer motion view transitions api

From CraftOS-dev/craftbot-agent-bundles · View interactive version

Framer motion view transitions api is an AI agent skill from the GitHub repository CraftOS-dev/craftbot-agent-bundles. Source: https://motion.dev/ · https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API

How to use this skill

Skill file

<!--

Source: https://motion.dev/ · https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API

Authored: June 2026 for the frontend-engineer agent bundle.

-->

Animation — motion + View Transitions API

motion is the 2024+ name for Framer Motion — now framework-agnostic

(React, Vue, Svelte, vanilla JS). The browser-native View Transitions API

(cross-browser stable in 2024) handles cross-page and cross-element morphs with

zero JS. Use both together: View Transitions for navigation; motion for

declarative gesture / spring animation.

When to use

"spring", "drag", "AnimatePresence", "shared element"

Setup

# motion (Framer rebrand) — React
pnpm add motion

# Vue
pnpm add motion-v

# Vanilla
pnpm add motion

# Auto-animate (list reorder, Formkit) — lightest possible option
pnpm add @formkit/auto-animate

Verify: pnpm list motion → 11.x or 12.x.

No API keys.

Common recipes — motion

Recipe 1 — Declarative animation

import { motion } from "motion/react";

<motion.div
  initial={{ opacity: 0, y: 20 }}
  animate={{ opacity: 1, y: 0 }}
  transition={{ duration: 0.3, ease: "easeOut" }}
>
  Hello
</motion.div>

Recipe 2 — Spring physics

<motion.div
  animate={{ x: 100 }}
  transition={{ type: "spring", stiffness: 260, damping: 20 }}
/>

Recipe 3 — `AnimatePresence` for exit animations

import { AnimatePresence, motion } from "motion/react";

function Modal({ open }: { open: boolean }) {
  return (
    <AnimatePresence>
      {open && (
        <motion.div
          key="modal"
          initial={{ opacity: 0, scale: 0.9 }}
          animate={{ opacity: 1, scale: 1 }}
          exit={{ opacity: 0, scale: 0.9 }}
          transition={{ duration: 0.2 }}
        >
          ...
        </motion.div>
      )}
    </AnimatePresence>
  );
}

Recipe 4 — Drag gestures

<motion.div
  drag
  dragConstraints={{ left: -100, right: 100, top: -100, bottom: 100 }}
  dragElastic={0.2}
  whileDrag={{ scale: 1.05 }}
/>

<motion.div
  drag="x"
  dragMomentum={false}
  onDragEnd={(_, info) => console.log("offset", info.offset.x)}
/>

Recipe 5 — `layout` animations (reorder lists, accordion)

import { motion, Reorder } from "motion/react";

function TodoList({ items, setItems }: { items: Todo[]; setItems: (t: Todo[]) => void }) {
  return (
    <Reorder.Group axis="y" values={items} onReorder={setItems}>
      {items.map((item) => (
        <Reorder.Item key={item.id} value={item} className="p-3 bg-white border rounded">
          {item.text}
        </Reorder.Item>
      ))}
    </Reorder.Group>
  );
}

Recipe 6 — `whileHover` / `whileTap` / `whileInView`

<motion.button
  whileHover={{ scale: 1.05 }}
  whileTap={{ scale: 0.95 }}
>
  Click me
</motion.button>

<motion.div
  initial={{ opacity: 0 }}
  whileInView={{ opacity: 1 }}
  viewport={{ once: true, amount: 0.3 }}
>
  Fades in once when 30% visible
</motion.div>

Recipe 7 — Variants for orchestrating

const container = {
  hidden: { opacity: 0 },
  visible: {
    opacity: 1,
    transition: { staggerChildren: 0.1 },
  },
};

const item = {
  hidden: { opacity: 0, y: 20 },
  visible: { opacity: 1, y: 0 },
};

<motion.ul variants={container} initial="hidden" animate="visible">
  {items.map((it) => (
    <motion.li key={it.id} variants={item}>{it.text}</motion.li>
  ))}
</motion.ul>

Recipe 8 — `useScroll` + `useTransform` (scroll-driven)

import { motion, useScroll, useTransform } from "motion/react";

function Parallax() {
  const { scrollY } = useScroll();
  const y = useTransform(scrollY, [0, 500], [0, -150]);
  return <motion.div style={{ y }}>Parallax</motion.div>;
}

Recipe 9 — Shared layout (cross-component morph)

{!isExpanded ? (
  <motion.div layoutId="card" onClick={() => setExpanded(true)} className="w-32 h-32 bg-blue-500" />
) : (
  <motion.div layoutId="card" onClick={() => setExpanded(false)} className="absolute inset-10 bg-blue-500" />
)}

The element morphs smoothly between layouts — same layoutId is the link.

Common recipes — View Transitions API

Recipe 10 — Single-page transition (DOM update)

async function navigate(href: string) {
  if (!document.startViewTransition) {
    // fallback for browsers without support
    location.assign(href);
    return;
  }
  document.startViewTransition(async () => {
    const html = await fetch(href).then((r) => r.text());
    document.documentElement.innerHTML = new DOMParser().parseFromString(html, "text/html").documentElement.innerHTML;
  });
}

Recipe 11 — Named shared elements (CSS view transitions)

/* Old page */
.hero {
  view-transition-name: hero;
}

/* New page — same name → automatic morph */
.product-image {
  view-transition-name: hero;
}

/* Customize the transition */
::view-transition-old(hero),
::view-transition-new(hero) {
  animation-duration: 300ms;
  animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

Recipe 12 — Astro View Transitions

---
import { ClientRouter } from "astro:transitions";
---
<html>
  <head>
    <ClientRouter />
  </head>
  <body>
    <main transition:name="main">
      <slot />
    </main>
  </body>
</html>

Astro wires the View Transitions API automatically.

Recipe 13 — Next 15 view transitions

"use client";
import { useRouter } from "next/navigation";

const router = useRouter();

function navigate(href: string) {
  if (!document.startViewTransition) return router.push(href);
  document.startViewTransition(() => router.push(href));
}

Next 15.x has experimental built-in support — check

experimental: { viewTransition: true } in next.config.ts.

Recipe 14 — Reduced motion

import { useReducedMotion } from "motion/react";

function FadeIn({ children }) {
  const reduce = useReducedMotion();
  return (
    <motion.div
      initial={{ opacity: 0 }}
      animate={{ opacity: 1 }}
      transition={{ duration: reduce ? 0 : 0.4 }}
    >
      {children}
    </motion.div>
  );
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Mandatory for WCAG compliance.

Common recipes — AutoAnimate

Recipe 15 — AutoAnimate (FormKit)

import { useAutoAnimate } from "@formkit/auto-animate/react";

function TodoList({ items }: { items: Todo[] }) {
  const [parent] = useAutoAnimate();
  return (
    <ul ref={parent}>
      {items.map((t) => <li key={t.id}>{t.text}</li>)}
    </ul>
  );
}

One hook → smooth add/remove/reorder. Smallest API surface for simple cases.

Examples

Example 1: Page-transition morph between list + detail

/* list page */
.product-card[data-id="42"] img { view-transition-name: product-42; }
/* detail page */
.product-detail img { view-transition-name: product-42; }

Astro / Next router triggers a document.startViewTransition on navigation;

the browser morphs product-42 between the two pages automatically.

Example 2: Drag-to-reorder list with motion

import { Reorder } from "motion/react";

const [items, setItems] = useState(initial);

<Reorder.Group axis="y" values={items} onReorder={setItems}>
  {items.map((i) => (
    <Reorder.Item key={i.id} value={i} whileDrag={{ scale: 1.02 }}>
      {i.text}
    </Reorder.Item>
  ))}
</Reorder.Group>

Edge cases / gotchas

still maintained but new APIs land in motion.

doesn't fire.

layout="position" to constrain.

return path, not in useEffect reading .get().

document.startViewTransition(callback); cross-document MPA needs

@view-transition { navigation: auto; } in CSS (Chrome 126+).

caniuse.com/view-transitions. Always feature-detect.

multiple elements have the same name, the API picks one (undefined which).

prefers-reduced-motion or you fail WCAG 2.3.3.

gold standard for complex timeline animations. Use when motion can't do it.

top/left. Stay on the compositor thread.

remove after.

Sources

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.