Animación Lottie — Animaciones Programáticas Basadas en JSON
Crea logotipos animados, iconos y microinteracciones como archivos Lottie JSON ligeros. No necesitas After Effects: construye animaciones completamente en código.
Resumen
- Formato: Lottie JSON (estándar abierto)
- Repositorio del reproductor: github.com/LottieFiles/lottie-player
- Repositorio del editor: github.com/marciogranzotto/lottie-tools (editor web de código abierto)
- Licencia: MIT
- Instalación:
npm install lottie-webonpm install @lottiefiles/lottie-player
¿Qué es Lottie?
Lottie es un formato de animación basado en JSON. Las animaciones se describen como propiedades con fotogramas clave en un archivo JSON estructurado. Se renderizan a cualquier resolución (basadas en vectores), son de tamaño reducido y se reproducen de forma nativa en web, iOS, Android y React Native.
Estructura JSON de Lottie
{
"v": "5.7.1", // Versión de Lottie
"fr": 30, // Fotogramas por segundo
"ip": 0, // Punto de inicio (fotograma inicial)
"op": 60, // Punto de fin (fotograma final) — 2 segundos a 30fps
"w": 400, // Ancho
"h": 400, // Alto
"assets": [], // Recursos externos (imágenes, precomposiciones)
"layers": [ // Capas de la animación (de abajo a arriba)
{
"ty": 4, // Capa de forma
"nm": "Círculo", // Nombre de la capa
"ip": 0,
"op": 60,
"st": 0, // Tiempo de inicio
"ks": { // Propiedades de transformación
"o": { "a": 0, "k": 100 }, // Opacidad (estática)
"r": { "a": 0, "k": 0 }, // Rotación
"p": { // Posición (animada)
"a": 1, // a=1 significa animado
"k": [
{ "t": 0, "s": [200, 300], "e": [200, 100], "i": {"x": 0.5, "y": 1}, "o": {"x": 0.5, "y": 0} },
{ "t": 30, "s": [200, 100] }
]
},
"s": { "a": 0, "k": [100, 100] } // Escala
},
"shapes": [...] // Definiciones de formas
}
]
}
Tipos de capa
| ty | Tipo | Descripción |
|---|---|---|
| 0 | Precomp | Composición anidada |
| 1 | Sólido | Capa de color sólido |
| 2 | Imagen | Capa de recurso de imagen |
| 3 | Nulo | Padre de transformación vacío |
| 4 | Forma | Formas vectoriales (más común) |
| 5 | Texto | Capa de texto |
Tipos de forma
| ty | Forma |
|---|---|
| "rc" | Rectángulo |
| "el" | Elipse |
| "sr" | Estrella/Polígono |
| "sh" | Trayecto (bezier) |
| "fl" | Relleno |
| "st" | Trazo |
| "gf" | Relleno degradado |
| "gs" | Trazo degradado |
| "tr" | Transformación |
| "gr" | Grupo |
Construir animaciones en código
Círculo con fundido de entrada simple
{
"v": "5.7.1",
"fr": 30,
"ip": 0,
"op": 30,
"w": 200,
"h": 200,
"layers": [{
"ty": 4,
"nm": "círculo",
"ip": 0,
"op": 30,
"st": 0,
"ks": {
"o": {
"a": 1,
"k": [
{"t": 0, "s": [0], "e": [100], "i": {"x": [0.4], "y": [1]}, "o": {"x": [0.6], "y": [0]}},
{"t": 20, "s": [100]}
]
},
"r": {"a": 0, "k": 0},
"p": {"a": 0, "k": [100, 100]},
"s": {
"a": 1,
"k": [
{"t": 0, "s": [0, 0], "e": [100, 100], "i": {"x": [0.2, 0.2], "y": [1, 1]}, "o": {"x": [0.8, 0.8], "y": [0, 0]}},
{"t": 25, "s": [100, 100]}
]
}
},
"shapes": [
{
"ty": "gr",
"it": [
{"ty": "el", "p": {"a": 0, "k": [0, 0]}, "s": {"a": 0, "k": [80, 80]}},
{"ty": "fl", "c": {"a": 0, "k": [0.2, 0.5, 1, 1]}, "o": {"a": 0, "k": 100}},
{"ty": "tr", "p": {"a": 0, "k": [0, 0]}, "s": {"a": 0, "k": [100, 100]}}
]
}
]
}]
}
Curvas de easing en fotogramas clave
// Ease in-out (suave)
"i": {"x": [0.42], "y": [1]},
"o": {"x": [0.58], "y": [0]}
// Ease out (decelerar)
"i": {"x": [0.0], "y": [1]},
"o": {"x": [0.6], "y": [0]}
// Ease in (acelerar)
"i": {"x": [0.4], "y": [1]},
"o": {"x": [1.0], "y": [0]}
// Lineal
"i": {"x": [1], "y": [1]},
"o": {"x": [0], "y": [0]}
Generación programática con JavaScript
function createLottieAnimation({ width, height, fps, durationFrames, layers }) {
return {
v: "5.7.1",
fr: fps,
ip: 0,
op: durationFrames,
w: width,
h: height,
assets: [],
layers,
};
}
function createShapeLayer({ name, startFrame, endFrame, shapes, transform }) {
return {
ty: 4,
nm: name,
ip: startFrame,
op: endFrame,
st: startFrame,
ks: transform,
shapes,
};
}
// Generar y guardar
const animation = createLottieAnimation({
width: 400, height: 400, fps: 30, durationFrames: 60,
layers: [/* ... */],
});
const fs = require("fs");
fs.writeFileSync("animation.json", JSON.stringify(animation, null, 2));
Reproducir Lottie en web
<!-- Mediante CDN -->
<script src="https://unpkg.com/@lottiefiles/lottie-player@latest/dist/lottie-player.js"></script>
<lottie-player src="animation.json" background="transparent" speed="1" loop autoplay></lottie-player>
// Mediante npm
import lottie from "lottie-web";
const anim = lottie.loadAnimation({
container: document.getElementById("lottie"),
renderer: "svg",
loop: true,
autoplay: true,
animationData: require("./animation.json"),
});
Usar Lottie en Remotion
import { Lottie } from "@remotion/lottie";
import animationData from "./animation.json";
export const MyScene: React.FC = () => {
return <Lottie animationData={animationData} />;
};
Instalación: npm install @remotion/lottie
Buenas prácticas
- Mantenlo simple — Menos capas = archivo más pequeño, mejor rendimiento
- Usa capas de forma en lugar de capas de imagen siempre que sea posible (vectorial = nítido en cualquier tamaño)
- Aplica easing a los fotogramas clave — Nunca uses easing lineal para movimiento orgánico
- 30fps es el estándar para animaciones Lottie en web
- Menos de 2 segundos para microinteracciones, 3-5 segundos para logotipos
- Prueba con lottie-player — Vista previa antes de embeber
- Optimiza — Elimina propiedades no utilizadas, minimiza la precisión de los números
Fuente de la skill del agente
- Wiggle (skill de animación de logotipos): github.com/talknerdytome-labs/wiggle-claude-skill
- Lottie Tools (editor): github.com/marciogranzotto/lottie-tools
- OmniLottie (generación por IA): github.com/OpenVGLab/OmniLottie