Communitygithub.com

Motion (Framer Motion) — Biblioteca de Animação React

Animações declarativas para React. Spring, gestos, animações de layout e transições de página. Acelerado por GPU, pronto para produção.

O que é Motion (Framer Motion) — Biblioteca de Animação React?

Esta skill fornece uma referência abrangente para Motion (anteriormente Framer Motion), a biblioteca de animação declarativa líder para React. Ela cobre desde animações básicas em componentes com `motion.div`, animações de saída com `AnimatePresence`, física de molas com parâmetros customizáveis, variantes para animações orquestradas de pais e filhos, gestos como hover e drag, animações de layout automáticas com o prop `layout`, e animações baseadas em scroll com os hooks `useScroll` e `useTransform`. A skill também inclui padrões comuns como transições de página, listas escalonadas e efeitos de hover em cartões. É útil para qualquer desenvolvedor React que queira criar interfaces de usuário fluidas e interativas com uma API declarativa e otimizada para performance. O resumo também compara Motion com GSAP, destacando quando usar cada um, e oferece boas práticas para animações sutis e eficientes.

Funciona com~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ever-just/agentskills/tree/HEAD/skills/framer-motion

Perguntar na sua IA favorita

Abre um novo chat com esta habilidade de agente já pré-carregada.

Documentação

Motion (Framer Motion) — Biblioteca de Animação para React UI

Animações declarativas para React. Spring, gestos, animações de layout e transições de página. Acelerado por GPU, pronto para produção.

Visão Geral

  • Repositório: github.com/motiondivision/motion (26K+ estrelas)
  • Linguagem: TypeScript / React
  • Licença: MIT
  • Instalação: npm install motion
  • Documentação: motion.dev
  • Nota: Framer Motion foi renomeado para Motion. Importe de motion/react.

API Principal

Animação Básica

import { motion } from "motion/react";

// Animar ao montar
<motion.div
  initial={{ opacity: 0, y: 20 }}
  animate={{ opacity: 1, y: 0 }}
  transition={{ duration: 0.5 }}
>
  Olá Mundo
</motion.div>

// Animar ao sair (requer AnimatePresence)
import { AnimatePresence } from "motion/react";

<AnimatePresence>
  {isVisible && (
    <motion.div
      initial={{ opacity: 0 }}
      animate={{ opacity: 1 }}
      exit={{ opacity: 0 }}
    >
      Conteúdo
    </motion.div>
  )}
</AnimatePresence>

Física de Mola

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

// Presets
transition={{ type: "spring", bounce: 0.5 }}  // 0 = sem bounce, 1 = muito elástico

Variantes (Animações Orquestradas)

const container = {
  hidden: { opacity: 0 },
  show: {
    opacity: 1,
    transition: {
      staggerChildren: 0.1,    // Atraso entre filhos
      delayChildren: 0.3,       // Atraso inicial
    },
  },
};

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

<motion.ul variants={container} initial="hidden" animate="show">
  {items.map((i) => (
    <motion.li key={i} variants={item}>{i}</motion.li>
  ))}
</motion.ul>

Gestos

// Hover
<motion.button
  whileHover={{ scale: 1.05 }}
  whileTap={{ scale: 0.95 }}
>
  Clique aqui
</motion.button>

// Arrastar
<motion.div
  drag                          // Habilita arrastar em ambos os eixos
  dragConstraints={{ left: -100, right: 100, top: -50, bottom: 50 }}
  dragElastic={0.2}
/>

Animações de Layout

// Animar automaticamente mudanças de layout
<motion.div layout>
  {isExpanded ? <ConteudoExpandido /> : <ConteudoRecolhido />}
</motion.div>

// Animação de layout compartilhada (morph entre elementos)
<motion.div layoutId="card">
  {/* Este elemento faz morph entre posições quando layoutId corresponde */}
</motion.div>

Animações de Scroll

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

function SecaoParalaxe() {
  const { scrollYProgress } = useScroll();
  const y = useTransform(scrollYProgress, [0, 1], [0, -200]);
  const opacity = useTransform(scrollYProgress, [0, 0.5, 1], [1, 1, 0]);

  return (
    <motion.div style={{ y, opacity }}>
      Conteúdo com paralaxe
    </motion.div>
  );
}

useAnimate (Imperativo)

import { useAnimate } from "motion/react";

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

  async function handleClick() {
    await animate(".box", { scale: 1.5 }, { duration: 0.3 });
    await animate(".box", { rotate: 360 }, { duration: 0.5 });
    await animate(".box", { scale: 1, rotate: 0 });
  }

  return (
    <div ref={scope}>
      <div className="box" onClick={handleClick}>Clique aqui</div>
    </div>
  );
}

Keyframes

<motion.div
  animate={{
    x: [0, 100, 100, 0, 0],
    y: [0, 0, 100, 100, 0],
    rotate: [0, 90, 180, 270, 360],
  }}
  transition={{ duration: 2, repeat: Infinity }}
/>

Tipos de Transição

// Spring (padrão para valores físicos)
transition={{ type: "spring", stiffness: 100, damping: 10 }}

// Tween (baseado em duração)
transition={{ type: "tween", duration: 0.5, ease: "easeInOut" }}

// Opções de easing
ease: "linear" | "easeIn" | "easeOut" | "easeInOut"
ease: [0.42, 0, 0.58, 1]  // Cubic bezier personalizado

// Repetir
transition={{ repeat: Infinity, repeatType: "reverse", duration: 1 }}

// Atraso
transition={{ delay: 0.5 }}

Padrões Comuns

Transição de Página

// No componente de layout
<AnimatePresence mode="wait">
  <motion.div
    key={pathname}
    initial={{ opacity: 0, x: 20 }}
    animate={{ opacity: 1, x: 0 }}
    exit={{ opacity: 0, x: -20 }}
    transition={{ duration: 0.3 }}
  >
    {children}
  </motion.div>
</AnimatePresence>

Lista Escalonada

const container = {
  hidden: {},
  show: { transition: { staggerChildren: 0.08 } },
};
const item = {
  hidden: { opacity: 0, y: 15 },
  show: { opacity: 1, y: 0, transition: { type: "spring", bounce: 0.3 } },
};

Cartão com Escala ao Hover

<motion.div
  whileHover={{ scale: 1.03, boxShadow: "0 10px 30px rgba(0,0,0,0.15)" }}
  transition={{ type: "spring", stiffness: 400, damping: 25 }}
/>

Melhores Práticas

  1. Use variantes para animações orquestradas de pais/filhos
  2. Física de mola para movimentos com sensação natural (evite easing linear)
  3. Prop layout para animações automáticas de mudanças de layout
  4. AnimatePresence necessário para animações de saída
  5. layoutId para transições de elementos compartilhados entre rotas
  6. useScroll para animações vinculadas ao scroll (paralaxe, barras de progresso)
  7. whileHover/whileTap para feedback interativo
  8. Escalonar filhos via transition.staggerChildren da variante
  9. Mantenha as animações sutis — duração de 0.2-0.5s para interações de UI
  10. Acelerado por GPU — Motion usa transformações por padrão

Quando Usar Motion vs GSAP

MotionGSAP
FrameworkPrimeiro ReactAgnóstico de framework
EstiloDeclarativo (props JSX)Imperativo (chamadas de função)
Animações de layoutIntegrado (mágico)Manual
ScrollHook useScrollPlugin ScrollTrigger
GestosIntegrado (arrastar, hover, toque)Plugin Draggable
Morphing SVGLimitadoPlugin MorphSVG
Tamanho do bundle~30KB~25KB core

Fonte

  • Repositório: github.com/motiondivision/motion
  • Documentação: motion.dev
  • Exemplos: motion.dev/docs/react-quick-start

Individual skills in this repo

This repo contains 9 individual skills — each has its own dedicated page.

ever-just/agentskills

> Create animated logos, icons, and micro-interactions as lightweight Lottie JSON files. No After Effects needed — build animations entirely in code.

ever-just/agentskills

> A TypeScript library using generators to program animations with a real-time editor. Ideal for explainer videos, code walkthroughs, and educational content.

ever-just/agentskills

> Add animated subtitles and captions to Remotion videos from .SRT files. TikTok-style word-by-word highlights, karaoke effects, and more.

ever-just/agentskills

> Create videos programmatically using React components. The most mature framework for code-driven video production.

ever-just/agentskills

> Copy-paste video components for Remotion. Intros, text effects, transitions, and full scene templates. Like shadcn/ui but for video.

ever-just/agentskills

Extract actionable intelligence from video content across YouTube, Vimeo, and company websites. Video reveals what text sources cannot: facility scale, team composition, product demonstrations, signage, event attendance, and operational reality.

ever-just/agentskills

Optimize and embed an existing video as a fast, crisp, autoplaying hero/background/loop on a website. Use when adding or replacing a video on a marketing site and it is too heavy, will not autoplay (especially on mobile/Safari), shows a codec error, or looks soft — to transcode it to web-safe H.264 with the right pixel format, faststart, retina-aware sizing, and a poster frame, then embed and verify it actually plays. This is optimization + embedding of footage you already have, not creating/animating a video (for that use remotion/moviepy/motion-canvas). Use when the user says "add this video to the site", "the hero video is too big / won't play / isn't crisp", "replace the homepage video", or "make this loop on the landing page".

ever-just/agentskills

Full conversion audit for any homepage or landing page. Use when someone asks to "review my homepage," "audit my landing page," "why isn't my page converting," "check my website," or wants feedback on their marketing page. Requires URL or screenshot before proceeding.

ever-just/agentskills

Automatically fetch YouTube video transcripts, generate structured summaries, and send full transcripts to messaging platforms. Detects YouTube URLs and provides metadata, key insights, and downloadable transcripts.

Habilidades Relacionadas