Lottieアニメーション — プログラムによるJSONベースのアニメーション
アニメーションロゴ、アイコン、マイクロインタラクションを軽量なLottie JSONファイルとして作成します。After Effectsは不要で、コードのみでアニメーションを構築できます。
概要
- 形式: Lottie JSON(オープンスタンダード)
- プレイヤーリポジトリ: github.com/LottieFiles/lottie-player
- エディタリポジトリ: github.com/marciogranzotto/lottie-tools(オープンソースWebエディタ)
- ライセンス: MIT
- インストール:
npm install lottie-webまたはnpm install @lottiefiles/lottie-player
Lottieとは
LottieはJSONベースのアニメーションフォーマットです。アニメーションは、構造化されたJSONファイル内のキーフレーム付きプロパティとして記述されます。ベクターベースで任意の解像度でレンダリングでき、ファイルサイズは非常に小さく、Web、iOS、Android、React Nativeでネイティブに再生されます。
Lottie JSONの構造
{
"v": "5.7.1", // Lottieバージョン
"fr": 30, // フレームレート
"ip": 0, // 開始フレーム
"op": 60, // 終了フレーム — 30fpsで2秒
"w": 400, // 幅
"h": 400, // 高さ
"assets": [], // 外部アセット(画像、プリコンポ)
"layers": [ // アニメーションレイヤー(下から上)
{
"ty": 4, // シェイプレイヤー
"nm": "Circle", // レイヤー名
"ip": 0,
"op": 60,
"st": 0, // 開始時間
"ks": { // トランスフォームプロパティ
"o": { "a": 0, "k": 100 }, // 不透明度(静的)
"r": { "a": 0, "k": 0 }, // 回転
"p": { // 位置(アニメーション)
"a": 1, // a=1はアニメーションあり
"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] } // スケール
},
"shapes": [...] // シェイプ定義
}
]
}
レイヤータイプ
| ty | タイプ | 説明 |
|---|---|---|
| 0 | プリコンポ | ネストされたコンポジション |
| 1 | ソリッド | 単色レイヤー |
| 2 | 画像 | 画像アセットレイヤー |
| 3 | ヌル | 空のトランスフォーム親 |
| 4 | シェイプ | ベクターシェイプ(最も一般的) |
| 5 | テキスト | テキストレイヤー |
シェイプタイプ
| ty | シェイプ |
|---|---|
| "rc" | 矩形 |
| "el" | 楕円 |
| "sr" | 星/多角形 |
| "sh" | パス(ベジェ) |
| "fl" | 塗り |
| "st" | 線 |
| "gf" | グラデーション塗り |
| "gs" | グラデーション線 |
| "tr" | トランスフォーム |
| "gr" | グループ |
コードでアニメーションを構築する
シンプルなフェードイン円
{
"v": "5.7.1",
"fr": 30,
"ip": 0,
"op": 30,
"w": 200,
"h": 200,
"layers": [{
"ty": 4,
"nm": "circle",
"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]}}
]
}
]
}]
}
キーフレームイージング
// イーズインアウト(スムーズ)
"i": {"x": [0.42], "y": [1]},
"o": {"x": [0.58], "y": [0]}
// イーズアウト(減速)
"i": {"x": [0.0], "y": [1]},
"o": {"x": [0.6], "y": [0]}
// イーズイン(加速)
"i": {"x": [0.4], "y": [1]},
"o": {"x": [1.0], "y": [0]}
// 線形
"i": {"x": [1], "y": [1]},
"o": {"x": [0], "y": [0]}
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,
};
}
// 生成して保存
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));
WebでLottieを再生する
<!-- 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>
// npm経由
import lottie from "lottie-web";
const anim = lottie.loadAnimation({
container: document.getElementById("lottie"),
renderer: "svg",
loop: true,
autoplay: true,
animationData: require("./animation.json"),
});
RemotionでLottieを使用する
import { Lottie } from "@remotion/lottie";
import animationData from "./animation.json";
export const MyScene: React.FC = () => {
return <Lottie animationData={animationData} />;
};
インストール: npm install @remotion/lottie
ベストプラクティス
- シンプルに保つ — レイヤーが少ないほどファイルが小さく、パフォーマンスが向上します
- シェイプレイヤーを使用する — 可能な限り画像レイヤーよりもシェイプレイヤーを使用します(ベクターはどんなサイズでも鮮明)
- キーフレームをイージングする — 有機的な動きには線形イージングを使用しないでください
- 30fpsがWeb Lottieアニメーションの標準です
- マイクロインタラクションは2秒未満、ロゴは3〜5秒に抑えます
- lottie-playerでテストする — 埋め込む前にプレビューします
- 最適化する — 未使用のプロパティを削除し、数値の精度を最小限に抑えます
エージェントスキルソース
- Wiggle(ロゴアニメーションスキル): github.com/talknerdytome-labs/wiggle-claude-skill
- Lottie Tools(エディタ): github.com/marciogranzotto/lottie-tools
- OmniLottie(AI生成): github.com/OpenVGLab/OmniLottie