Mit freundlicher Unterstützung von
← Zurück zu Mediendesign & Digitale Medien
Framer Motion (seit November 2024 unter dem Namen Motion) ist eine deklarative Animations-Bibliothek für React, die physikbasierte Spring-Animationen, einfache Gesten-Unterstützung und komponentenübergreifende Übergänge in das React-Ökosystem integriert.

Was ist Framer Motion?

Framer Motion entstand bei Framer, dem Prototyping-Tool-Unternehmen, und wurde von Matt Perry entwickelt. Am 12. November 2024 kündigte er an, dass das Projekt mit Zustimmung von Framer unabhängig wird und den Namen Motion trägt; das Package heißt motion, Importe laufen über motion/react. Das Package framer-motion wird laut npm weiterhin parallel veröffentlicht (Stand November 2026: beide in Version 14.9.1), die Motion-Dokumentation beschreibt aber den Umstieg auf motion. Für neue Projekte empfiehlt sich das Package motion.

Das Besondere: Motion folgt dem deklarativen Paradigma von React. Statt gsap.to(element, {x: 100}) schreibt man <motion.div animate={{ x: 100 }}>. Die Bibliothek übernimmt die Umsetzung intern und nutzt, wo möglich, die Web Animations API des Browsers.

Version 12 erschien im Januar 2025 und brachte laut Upgrade-Guide keine Breaking Changes für React. Version 13 entfernte die optionale Abhängigkeit @emotion/is-prop-valid, was vor allem Nutzer/innen von Styled Components und Emotion betrifft; Version 14 brachte wieder keine Breaking Changes. animate() steht auch außerhalb von React als eigenständige Funktion zur Verfügung.

Erklärung

Installation und Grundkonzept

``bash npm install motion npm install framer-motion ``

```jsx // Aktueller Import (Package "motion") import { motion } from 'motion/react'; // Legacy Import (Package "framer-motion") // import { motion } from 'framer-motion';

// Jedes HTML-Element hat ein motion-Äquivalent <motion.div initial={{ opacity: 0, y: 20 }} animate={{ opacity: 1, y: 0 }} exit={{ opacity: 0, y: -20 }} transition={{ duration: 0.4, ease: 'easeOut' }} > Animierter Inhalt </motion.div> ```

motion.div, motion.span, motion.button usw. sind direkte Drop-in-Ersetzungen für normale HTML-Elemente.

Variants: Zustände zentralisieren

Variants erlauben die Zentralisierung von Animationszuständen und Weitergabe an Kinder:

```jsx const containerVariants = { versteckt: { opacity: 0 }, sichtbar: { opacity: 1, transition: { staggerChildren: 0.08, // Kinder gestaffelt delayChildren: 0.2 } } };

const elementVariants = { versteckt: { opacity: 0, y: 30 }, sichtbar: { opacity: 1, y: 0 } };

function AnimierteList({ items }) { return ( <motion.ul variants={containerVariants} initial="versteckt" animate="sichtbar" > {items.map(item => ( <motion.li key={item.id} variants={elementVariants}> {item.text} </motion.li> ))} </motion.ul> ); } ```

Kinder-Elemente erben die initial und animate-Prop vom Parent, man muss sie nicht wiederholen.

Spring-Animationen

Framer Motion's größte Stärke sind physikbasierte Spring-Animationen:

```jsx // Type "spring" für federnde Bewegungen <motion.div animate={{ x: 200 }} transition={{ type: 'spring', stiffness: 300, // Federsteifigkeit (höher = schneller) damping: 25, // Dämpfung (niedriger = mehr Federn) mass: 1 // Masse des Objekts }} />

// Vordefinierte Spring-Presets transition={{ type: 'spring', bounce: 0.4 }} // 0 = kein Bounce, 1 = viel

// Snap: Abrupt, kein Federschwingen transition={{ type: 'spring', damping: 100 }} ```

AnimatePresence: Exit-Animationen

Das Herausragende an Framer Motion ist AnimatePresence, es ermöglicht Exit-Animationen, bevor ein Komponente aus dem DOM entfernt wird:

```jsx import { AnimatePresence, motion } from 'motion/react';

function Modal({ istOffen, zuSchliessen }) { return ( <AnimatePresence> {istOffen && ( <motion.div key="modal" className="modal-overlay" initial={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }} onClick={zuSchliessen} > <motion.div className="modal-inhalt" initial={{ scale: 0.9, y: 40 }} animate={{ scale: 1, y: 0 }} exit={{ scale: 0.9, y: -20, opacity: 0 }} transition={{ type: 'spring', damping: 25 }} onClick={e => e.stopPropagation()} > {/ Modal-Inhalt /} </motion.div> </motion.div> )} </AnimatePresence> ); } ```

useAnimate Hook

Für Abläufe, die per Code gesteuert werden, empfiehlt die Motion-Dokumentation den Hook useAnimate:

```jsx import { useAnimate } from 'motion/react';

function AnimiertesElement() { const [scope, animate] = useAnimate();

async function starteSequenz() { await animate(scope.current, { x: 100, opacity: 0.5 }); await animate(scope.current, { x: 200, opacity: 1 }); animate(scope.current, { x: 0 }); }

return ( <div ref={scope} onClick={starteSequenz}> Klick mich </div> ); } ```

Scroll-Animationen (useInView, useScroll)

```jsx import { motion, useInView, useScroll, useTransform } from 'motion/react'; import { useRef } from 'react';

// Element bei Scroll einblenden function ScrollElement() { const ref = useRef(null); const isInView = useInView(ref, { once: true, margin: '-100px' });

return ( <motion.div ref={ref} initial={{ opacity: 0, y: 60 }} animate={isInView ? { opacity: 1, y: 0 } : {}} transition={{ duration: 0.6, ease: 'easeOut' }} > Erscheint beim Scrollen </motion.div> ); }

// Parallax mit useScroll/useTransform function ParallaxHero() { const { scrollY } = useScroll(); const y = useTransform(scrollY, [0, 500], [0, -150]);

return ( <div className="hero"> <motion.img src="/hintergrund.jpg" style={{ y }} /> </div> ); } ```

Layout-Animationen

```jsx // Automatische Animation bei Layout-Änderungen import { motion, LayoutGroup } from 'motion/react';

function DynamischeList({ items, sortierung }) { return ( <LayoutGroup> {items.map(item => ( <motion.div key={item.id} layout // Animiert automatisch bei Position-Änderung transition={{ type: 'spring', damping: 20 }} > {item.text} </motion.div> ))} </LayoutGroup> ); } ```

Beispiele

Tab-Navigation mit shared layout

```jsx function Tabs({ tabs }) { const [aktiv, setAktiv] = useState(tabs[0].id);

return ( <div className="tabs"> {tabs.map(tab => ( <button key={tab.id} onClick={() => setAktiv(tab.id)} style={{ position: 'relative' }} > {tab.label} {aktiv === tab.id && ( <motion.div className="tab-indikator" layoutId="tab-indikator" // Gleiches layoutId = shared layout style={{ position: 'absolute', bottom: 0, left: 0, right: 0 }} /> )} </button> ))} </div> ); } ```

Gestensteuerung: Drag und Swipe

``jsx <motion.div drag="x" dragConstraints={{ left: -100, right: 100 }} dragElastic={0.1} whileDrag={{ scale: 1.05 }} onDragEnd={(event, { velocity, offset }) => { if (Math.abs(offset.x) > 100) { // Swipe-Aktion ausführen naechsteKarte(); } }} > Wischbare Karte </motion.div> ``

In der Praxis

prefers-reduced-motion in Framer Motion:

```jsx import { useReducedMotion } from 'motion/react';

function AnimiertesElement() { const reduzierteBewegung = useReducedMotion();

return ( <motion.div initial={{ opacity: 0, y: reduzierteBewegung ? 0 : 40 }} animate={{ opacity: 1, y: 0 }} > Inhalt </motion.div> ); } ```

Vergleich & Abgrenzung

Framer MotionGSAP (GreenSock), GrundlagenWeb Animations API (WAAPI)
React-IntegrationNativeExternExtern
Exit-AnimationenAnimatePresenceManuellManuell
Spring-PhysikExzellentMit Elastic-EaseNein
Layout-AnimationenAutomatischManuellManuell
Nicht-Reactanimate() für JavaScript, auch Vue-VarianteJaNativ

Häufige Fragen

Kann ich Framer Motion ohne React nutzen? Die React-Komponenten (motion.div usw.) sind für React. Motion bietet aber auch eine Variante für Vue und die Funktion animate() für Vanilla JavaScript (siehe motion.dev).

Wie groß ist Framer Motion? Laut Motion-Dokumentation etwa 43 kB für die motion-Komponente (tree-shaken); mit der m-Komponente und LazyMotion sinkt der initiale Umfang auf gut 5 kB, Feature-Pakete kommen bei Bedarf hinzu.

Was ist der Unterschied zwischen Motion und Motion One? Motion One war eine kleine Vanilla-JS-Bibliothek, die unter dem npm-Namen motion erschien (zuletzt Version 10.18, Juni 2024). Seit November 2024 steht der Name motion für die vereinheitlichte Bibliothek, die React, Vue und Vanilla JavaScript abdeckt.

Verwandte Einträge

Weiterführend

  • Motion: Dokumentation für React.
  • Motion: Upgrade guide.
  • Motion: Reduce bundle size.
  • npm: Pakete motion und framer-motion (Versionsverlauf).
  • Perry, Matt (2024): Framer Motion is now independent, introducing Motion. 12. November 2024,
  • Motion: useAnimate.
← Zurück zu Mediendesign & Digitale Medien
Infotag

Sei am Mittwoch dabei.
Bring Eltern oder Freunde mit.

Ein halber Nachmittag, der dir drei Jahre Klarheit bringen kann. Kostenlos, unverbindlich, ehrlich.

  • Rundgang durch Studios, Schnitträume und Tonstudio
  • Echte Absolventenfilme sehen
  • 1:1-Beratung zu Bewerbung & BAföG
  • Studierende direkt fragen
  • Kaffee, kein Sales-Pitch
  • Auch online möglich

Platz beim Infotag reservieren

Dauert 30 Sekunden. Bestätigung per E-Mail.
100 % kostenlos · keine Verpflichtung · jederzeit absagbar