Lottie 애니메이션은(는) 무엇을 하나요?
개요
Lottie는 After Effects 애니메이션을 웹, iOS, Android 및 React Native에서 실시간으로 렌더링하는 라이브러리입니다. Airbnb가 만들었으며, 디자이너가 정적 에셋을 제공하듯 쉽게 애니메이션을 제공할 수 있도록 합니다. 애니메이션은 After Effects에서 Bodymovin 플러그인을 사용하여 JSON 파일로 내보내지며, 최소한의 성능 오버헤드로 네이티브하게 렌더링됩니다.
Lottie를 사용해야 하는 경우:
- 디자이너가 제작하여 픽셀 완벽한 충실도가 필요한 애니메이션
- 복잡한 애니메이션 아이콘 및 마이크로 인터랙션
- 로딩 애니메이션 및 진행 표시기
- 온보딩 시퀀스 및 튜토리얼 애니메이션
- 마케팅 애니메이션 및 프로모션 콘텐츠
- GIF/비디오 대안으로 더 작은 파일 크기와 확장성
주요 장점:
- 벡터 기반 (품질 손실 없이 확장 가능)
- GIF나 비디오보다 파일 크기가 훨씬 작음
- 런타임에 편집 가능 (색상, 속도, 세그먼트)
- After Effects를 통한 완전한 디자이너 제어
- 플랫폼 간 렌더링 일관성
- 대화형 제어 (재생, 일시 중지, 탐색, 반복)
핵심 개념
Lottie 형식 유형
1. JSON Lottie (.json)
- 원래 Lottie 형식
- After Effects에서 Bodymovin 플러그인을 통해 내보내기
- 사람이 읽을 수 있는 JSON 구조
- 더 큰 파일 크기 (압축되지 않음)
- 모든 플랫폼에서 광범위하게 지원
2. dotLottie (.lottie)
- 최신 압축 형식
- JSON + 에셋을 포함하는 ZIP 아카이브
- 하나의 파일에서 여러 애니메이션 및 테마 지원
- 더 작은 파일 크기 (최대 90% 감소)
- 프로덕션 사용에 권장
라이브러리 옵션
lottie-web (원래 라이브러리):
import lottie from 'lottie-web';
lottie.loadAnimation({
container: document.getElementById('lottie-container'),
renderer: 'svg', // 또는 'canvas', 'html'
loop: true,
autoplay: true,
path: 'animation.json' // 또는 animationData: jsonData
});
@lottiefiles/dotlottie-web (최신, 권장):
import { DotLottie } from '@lottiefiles/dotlottie-web';
new DotLottie({
canvas: document.getElementById('canvas'),
src: 'animation.lottie',
autoplay: true,
loop: true
});
@lottiefiles/dotlottie-react (React 통합):
import { DotLottieReact } from '@lottiefiles/dotlottie-react';
<DotLottieReact
src="animation.lottie"
loop
autoplay
style={{ height: 300 }}
/>
lottie-react (대체 React 래퍼):
import Lottie from 'lottie-react';
import animationData from './animation.json';
<Lottie animationData={animationData} loop={true} />
애니메이션 데이터 소스
1. LottieFiles (lottie.host)
- 100,000개 이상의 무료 애니메이션
- 직접 URL 임베딩
- CDN 호스팅
2. 로컬 JSON/dotLottie 파일
- 애플리케이션과 함께 번들
- 더 나은 성능 (네트워크 요청 없음)
- 버전 관리에 유리
3. After Effects 내보내기
- 맞춤형 디자이너 애니메이션
- Bodymovin 플러그인 필요
- 파일 크기에 중요한 내보내기 설정
일반적인 패턴
1. dotLottie-web을 사용한 기본 HTML 통합
<!DOCTYPE html>
<html>
<head>
<style>
#canvas {
width: 400px;
height: 400px;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<script type="module">
import { DotLottie } from 'https://cdn.jsdelivr.net/npm/@lottiefiles/dotlottie-web/+esm';
new DotLottie({
canvas: document.getElementById('canvas'),
src: 'https://lottie.host/4db68bbd-31f6-4cd8-84eb-189de081159a/IGmMCqhzpt.lottie',
autoplay: true,
loop: true
});
</script>
</body>
</html>
2. 컨트롤이 있는 React 컴포넌트
import React from 'react';
import { DotLottieReact } from '@lottiefiles/dotlottie-react';
const AnimatedButton = () => {
const [dotLottie, setDotLottie] = React.useState(null);
const handlePlay = () => dotLottie?.play();
const handlePause = () => dotLottie?.pause();
const handleStop = () => dotLottie?.stop();
const handleSeek = (frame) => dotLottie?.setFrame(frame);
return (
<div>
<DotLottieReact
src="button-animation.lottie"
loop
autoplay={false}
dotLottieRefCallback={setDotLottie}
style={{ height: 200 }}
/>
<div>
<button onClick={handlePlay}>Play</button>
<button onClick={handlePause}>Pause</button>
<button onClick={handleStop}>Stop</button>
<button onClick={() => handleSeek(30)}>Seek to frame 30</button>
</div>
</div>
);
};
3. 이벤트 리스너 및 생명주기 훅
import React, { useEffect } from 'react';
import { DotLottieReact } from '@lottiefiles/dotlottie-react';
const EventDrivenAnimation = () => {
const [dotLottie, setDotLottie] = React.useState(null);
useEffect(() => {
if (!dotLottie) return;
const onLoad = () => console.log('Animation loaded');
const onPlay = () => console.log('Animation started');
const onPause = () => console.log('Animation paused');
const onComplete = () => console.log('Animation completed');
const onFrame = ({ currentFrame }) => console.log('Frame:', currentFrame);
dotLottie.addEventListener('load', onLoad);
dotLottie.addEventListener('play', onPlay);
dotLottie.addEventListener('pause', onPause);
dotLottie.addEventListener('complete', onComplete);
dotLottie.addEventListener('frame', onFrame);
return () => {
dotLottie.removeEventListener('load', onLoad);
dotLottie.removeEventListener('play', onPlay);
dotLottie.removeEventListener('pause', onPause);
dotLottie.removeEventListener('complete', onComplete);
dotLottie.removeEventListener('frame', onFrame);
};
}, [dotLottie]);
return (
<DotLottieReact
src="animation.lottie"
loop
autoplay
dotLottieRefCallback={setDotLottie}
/>
);
};
4. lottie-react를 사용한 스크롤 기반 애니메이션
import Lottie from 'lottie-react';
import robotAnimation from './robot.json';
const ScrollAnimation = () => {
const interactivity = {
mode: 'scroll',
actions: [
{
visibility: [0, 0.2],
type: 'stop',
frames: [0]
},
{
visibility: [0.2, 0.45],
type: 'seek',
frames: [0, 45]
},
{
visibility: [0.45, 1.0],
type: 'loop',
frames: [45, 60]
}
]
};
return (
<Lottie
animationData={robotAnimation}
style={{ height: 300 }}
interactivity={interactivity}
/>
);
};
5. 호버 트리거 세그먼트 재생
import { useLottie, useLottieInteractivity } from 'lottie-react';
import likeButton from './like-button.json';
const HoverAnimation = () => {
const lottieObj = useLottie({
animationData: likeButton
});
const Animation = useLottieInteractivity({
lottieObj,
mode: 'cursor',
actions: [
{
position: { x: [0, 1], y: [0, 1] },
type: 'loop',
frames: [45, 60]
},
{
position: { x: -1, y: -1 },
type: 'stop',
frames: [45]
}
]
});
return <div style={{ height: 300, border: '2px solid black' }}>{Animation}</div>;
};
6. 다중 애니메이션 및 테마 지원
import { DotLottieReact } from '@lottiefiles/dotlottie-react';
import React, { useState, useEffect } from 'react';
const ThemedAnimation = () => {
const [dotLottie, setDotLottie] = useState(null);
const [animations, setAnimations] = useState([]);
const [themes, setThemes] = useState([]);
const [currentAnimationId, setCurrentAnimationId] = useState('');
const [currentThemeId, setCurrentThemeId] = useState('');
useEffect(() => {
if (!dotLottie) return;
const onLoad = () => {
setAnimations(dotLottie.manifest.animations || []);
setThemes(dotLottie.manifest.themes || []);
setCurrentAnimationId(dotLottie.activeAnimationId);
setCurrentThemeId(dotLottie.activeThemeId);
};
dotLottie.addEventListener('load', onLoad);
return () => dotLottie.removeEventListener('load', onLoad);
}, [dotLottie]);
return (
<div>
<DotLottieReact
src="multi-animation.lottie"
dotLottieRefCallback={setDotLottie}
animationId={currentAnimationId}
themeId={currentThemeId}
/>
{themes.length > 0 && (
<select value={currentThemeId} onChange={(e) => setCurrentThemeId(e.target.value)}>
{themes.map((theme) => (
<option key={theme.id} value={theme.id}>{theme.id}</option>
))}
</select>
)}
{animations.length > 0 && (
<select value={currentAnimationId} onChange={(e) => setCurrentAnimationId(e.target.value)}>
{animations.map((anim) => (
<option key={anim.id} value={anim.id}>{anim.id}</option>
))}
</select>
)}
</div>
);
};
7. 성능을 위한 웹 워커 (DotLottieWorker)
import { DotLottieWorker } from '@lottiefiles/dotlottie-web';
// 애니메이션 렌더링을 웹 워커로 오프로드
new DotLottieWorker({
canvas: document.getElementById('canvas'),
src: 'heavy-animation.lottie',
autoplay: true,
loop: true,
workerId: 'worker-1' // worker별로 여러 애니메이션 그룹화
});
// 별도의 워커에서 여러 애니메이션
new DotLottieWorker({
canvas: document.getElementById('canvas-2'),
src: 'animation-2.lottie',
autoplay: true,
loop: true,
workerId: 'worker-2'
});
통합 패턴
GSAP ScrollTrigger와 함께 사용
import Lottie from 'lottie-react';
import gsap from 'gsap';
import ScrollTrigger from 'gsap/ScrollTrigger';
import animationData from './animation.json';
gsap.registerPlugin(ScrollTrigger);
const GSAPLottieIntegration = () => {
const lottieRef = React.useRef();
React.useEffect(() => {
const anim = lottieRef.current;
if (!anim) return;
// Lottie를 스크롤과 동기화
gsap.to(anim, {
scrollTrigger: {
trigger: '#animation-section',
start: 'top center',
end: 'bottom center',
scrub: 1,
onUpdate: (self) => {
const frame = Math.floor(self.progress * (anim.totalFrames - 1));
anim.goToAndStop(frame, true);
}
}
});
}, []);
return (
<div id="animation-section" style={{ height: '200vh' }}>
<Lottie
lottieRef={lottieRef}
animationData={animationData}
autoplay={false}
loop={false}
/>
</div>
);
};
Framer Motion과 함께 사용
import { motion } from 'framer-motion';
import { DotLottieReact } from '@lottiefiles/dotlottie-react';
const MotionLottie = () => {
return (
<motion.div
initial={{ opacity: 0, scale: 0.8 }}
animate={{ opacity: 1, scale: 1 }}
transition={{ duration: 0.6 }}
>
<DotLottieReact
src="animation.lottie"
loop
autoplay
style={{ height: 400 }}
/>
</motion.div>
);
};
Vue 3 통합
<script setup>
import { DotLottieVue } from '@lottiefiles/dotlottie-vue';
</script>
<template>
<DotLottieVue
style="height: 500px; width: 500px"
autoplay
loop
src="https://path-to-animation.lottie"
/>
</template>
Svelte 통합
<script lang="ts">
import { DotLottieSvelte } from '@lottiefiles/dotlottie-svelte';
import type { DotLottie } from '@lottiefiles/dotlottie-svelte';
let dotLottie: DotLottie | null = null;
function play() {
dotLottie?.play();
}
</script>
<DotLottieSvelte
src="animation.lottie"
loop={true}
autoplay={true}
dotLottieRefCallback={(ref) => dotLottie = ref}
/>
<button on:click={play}>Play</button>
성능 최적화
파일 크기 최적화
1. After Effects 내보내기 설정:
- "사용되지 않는 이미지 건너뛰기" 활성화
- 가능하면 글꼴 대신 "Glyphs" 사용
- 경로 단순화 (Illustrator에서 포인트 줄이기)
- 큰 데이터를 생성하는 효과(파티클, 노이즈) 피하기
- 벡터 레이어 대신 셰이프 레이어 사용
2. 압축:
- 자동 압축을 위해 dotLottie 형식(.lottie) 사용
- Lottie 최적화 도구를 통해 JSON 실행
- 불필요한 메타데이터 제거
3. 지연 로딩:
const LazyLottie = () => {
const [shouldLoad, setShouldLoad] = React.useState(false);
React.useEffect(() => {
const observer = new IntersectionObserver((entries) => {
if (entries[0].isIntersecting) {
setShouldLoad(true);
}
});
observer.observe(document.getElementById('lottie-trigger'));
return () => observer.disconnect();
}, []);
return (
<div id="lottie-trigger">
{shouldLoad && <DotLottieReact src="animation.lottie" loop autoplay />}
</div>
);
};
런타임 성능
1. 렌더러 선택:
// SVG: 최고 품질, 복잡한 애니메이션에 느림
// Canvas: 더 나은 성능, 래스터화됨
// HTML: 제한된 지원, 간단한 애니메이션에만 사용
// 복잡한 애니메이션의 경우 Canvas 선호
new DotLottie({
canvas: document.getElementById('canvas'),
src: 'animation.lottie',
autoplay: true,
loop: true,
renderConfig: {
devicePixelRatio: window.devicePixelRatio || 1
}
});
2. 웹 워커:
// 무거운 애니메이션을 워커로 오프로드
import { DotLottieWorker } from '@lottiefiles/dotlottie-web';
new DotLottieWorker({
canvas: document.getElementById('canvas'),
src: 'heavy-animation.lottie',
autoplay: true,
loop: true
});
3. 모바일 최적화:
// 모바일에서 품질 낮추기
const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
new DotLottie({
canvas: document.getElementById('canvas'),
src: isMobile ? 'animation-low.lottie' : 'animation-high.lottie',
autoplay: true,
loop: true,
renderConfig: {
devicePixelRatio: isMobile ? 1 : window.devicePixelRatio
}
});
일반적인 함정
1. 잘못된 정리로 인한 메모리 누수
문제: 컴포넌트가 마운트 해제될 때 Lottie 인스턴스를 제거하지 않음.
해결책:
const SafeAnimation = () => {
const [dotLottie, setDotLottie] = React.useState(null);
React.useEffect(() => {
return () => {
if (dotLottie) {
dotLottie.destroy();
}
};
}, [dotLottie]);
return (
<DotLottieReact
src="animation.lottie"
loop
autoplay
dotLottieRefCallback={setDotLottie}
/>
);
};
2. 잘못된 렌더러 사용
문제: 복잡한 애니메이션에 SVG를 사용하여 성능 저하.
해결책: 복잡한 애니메이션은 Canvas를, 간단한 애니메이션은 SVG를 사용하세요.
3. 지원되지 않는 After Effects 기능
문제: Bodymovin에서 지원되지 않는 After Effects 효과 사용.
해결책: 표현식, 3D 레이어, 파티클 효과 사용을 피하세요. LottieFiles 문서에서 호환성 표를 확인하세요.
모범 사례
- dotLottie 형식 사용 - 파일을 더 작고 빠르게 만듭니다.
- 지연 로딩 - 필요한 경우에만 애니메이션을 로드하세요.
- Canvas 렌더러 사용 - 복잡한 애니메이션의 경우 Canvas를 사용하세요.
- 디자인에 대한 제약 조건 - 디자이너와 성능 제약 조건을 논의하세요.
- 장치별 버전 - 저사양 장치용 저품질 애니메이션을 제공하세요.
- Animate 이벤트 - 부드러운 사용자 경험을 위해 애니메이션 이벤트를 사용하세요.
- 정리 - 메모리 누수를 피하기 위해 항상 Lottie 인스턴스를 제거하세요.
- 대체 콘텐츠 - 성능이나 네트워크 문제에 대비해 대체 콘텐츠를 제공하세요.
문제 해결
Q: 애니메이션이 표시되지 않습니다.
- JavaScript 콘솔에서 오류를 확인하세요.
- 파일 경로 또는 URL이 올바른지 확인하세요.
- container 또는 canvas 요소가 DOM에 존재하는지 확인하세요.
Q: 애니메이션 성능이 느립니다.
- Canvas 렌더러로 전환하세요.
- dotLottie 형식을 사용하세요.
- 애니메이션의 복잡성을 줄이세요.
- Web Worker를 사용하세요.
Q: 파일 크기가 너무 큽니다.
- dotLottie 형식을 사용하세요.
- After Effects 파일을 최적화하세요.
- LottieFiles 최적화 도구를 사용하세요.
- 불필요한 프레임을 제거하세요.
Q: 모바일에서 버벅입니다.
- devicePixelRatio를 1로 낮추세요.
- Canvas 렌더러를 사용하세요.
- Web Worker를 사용하세요.
- 더 간단한 애니메이션 버전을 제공하세요.