Skip to content
Skillv1.0.0

lottie

Play After Effects animations on web and mobile with Lottie — load JSON animation files, control playback, listen to events, and integrate animations into React, Vue, or vanilla JS apps. Use when task

by terminalskills(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from terminalskills/skills (skills/lottie/SKILL.md). Install upstream with npx skills add terminalskills/skills --skill lottie. Copyright stays with the author (Apache-2.0).

Lottie

Render After Effects animations exported as JSON. Lightweight, scalable, and interactive.

Setup

# Install lottie-web for vanilla JS/TS projects.
npm install lottie-web

Basic Playback

// src/lottie/player.ts — Load and play a Lottie animation in a DOM container.
// The animation JSON is typically exported from After Effects via Bodymovin.
import lottie, { AnimationItem } from "lottie-web";

export function playAnimation(
  container: HTMLElement,
  animationData: object
): AnimationItem {
  return lottie.loadAnimation({
    container,
    renderer: "svg", // "canvas" or "html" also available
    loop: true,
    autoplay: true,
    animationData,
  });
}

// Load from URL instead of inline data
export function playFromUrl(container: HTMLElement, path: string): AnimationItem {
  return lottie.loadAnimation({
    container,
    renderer: "svg",
    loop: true,
    autoplay: true,
    path, // URL to the JSON file
  });
}

Playback Controls

// src/lottie/controls.ts — Control animation playback: play, pause, seek, speed.
import type { AnimationItem } from "lottie-web";

export function setupControls(anim: AnimationItem) {
  // Play / Pause
  anim.play();
  anim.pause();
  anim.stop();

  // Go to specific frame (frame 30, and play)
  anim.goToAndPlay(30, true);

  // Go to specific frame and stop
  anim.goToAndStop(0, true);

  // Playback speed (2x)
  anim.setSpeed(2);

  // Play direction (-1 = reverse)
  anim.setDirection(-1);

  // Play only a segment (frames 10-50)
  anim.playSegments([10, 50], true);
}

Event Handling

// src/lottie/events.ts — Listen to animation lifecycle events for triggering
// UI updates, chaining animations, or tracking analytics.
import type { AnimationItem } from "lottie-web";

export function attachEvents(anim: AnimationItem) {
  anim.addEventListener("complete", () => {
    console.log("Animation completed");
  });

  anim.addEventListener("loopComplete", () => {
    console.log("Loop finished");
  });

  anim.addEventListener("enterFrame", (e) => {
    // Fires every frame — use sparingly
    const progress = (e as any).currentTime / anim.totalFrames;
    document.getElementById("progress")!.style.width = `${progress * 100}%`;
  });

  anim.addEventListener("DOMLoaded", () => {
    console.log("Animation DOM elements ready");
  });
}

React Integration

// src/components/LottiePlayer.tsx — React component wrapping lottie-web.
// Handles cleanup on unmount and exposes ref for external control.
import { useEffect, useRef } from "react";
import lottie, { AnimationItem } from "lottie-web";

interface Props {
  animationData: object;
  loop?: boolean;
  autoplay?: boolean;
  className?: string;
}

export function LottiePlayer({ animationData, loop = true, autoplay = true, className }: Props) {
  const containerRef = useRef<HTMLDivElement>(null);
  const animRef = useRef<AnimationItem | null>(null);

  useEffect(() => {
    if (!containerRef.current) return;

    animRef.current = lottie.loadAnimation({
      container: containerRef.current,
      renderer: "svg",
      loop,
      autoplay,
      animationData,
    });

    return () => {
      animRef.current?.destroy();
    };
  }, [animationData, loop, autoplay]);

  return <div ref={containerRef} className={className} />;
}

Dynamic Color Updates

// src/lottie/theme.ts — Modify colors inside a Lottie JSON before rendering.
// Useful for theming animations to match brand colors at runtime.
export function recolorAnimation(
  animationData: any,
  colorMap: Record<string, [number, number, number]>
): any {
  const data = JSON.parse(JSON.stringify(animationData));

  function walkShapes(shapes: any[]) {
    for (const shape of shapes) {
      if (shape.ty === "fl" && shape.c?.k) {
        const hex = rgbToHex(shape.c.k[0], shape.c.k[1], shape.c.k[2]);
        if (colorMap[hex]) {
          const [r, g, b] = colorMap[hex];
          shape.c.k = [r, g, b, 1];
        }
      }
      if (shape.it) walkShapes(shape.it);
    }
  }

  for (const layer of data.layers || []) {
    if (layer.shapes) walkShapes(layer.shapes);
  }

  return data;
}

function rgbToHex(r: number, g: number, b: number): string {
  return "#" + [r, g, b].map((v) => Math.round(v * 255).toString(16).padStart(2, "0")).join("");
}

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/terminalskills-skills-lottie/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

terminalskills-skills-lottie.ocm.jsonjson
{
  "ocm": "1",
  "id": "terminalskills-skills-lottie",
  "kind": "skill",
  "name": "lottie",
  "description": "Play After Effects animations on web and mobile with Lottie — load JSON animation files, control playback, listen to events, and integrate animations into React, Vue, or vanilla JS apps. Use when tasks involve adding motion graphics, animated icons, loading indicators, or micro-interactions exported from After Effects or other animation tools.",
  "publisher": "terminalskills",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "general"
    ],
    "tags": [
      "skill-md",
      "lottie",
      "animation",
      "after-effects",
      "motion",
      "micro-interactions",
      "skills-sh"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "Play After Effects animations on web and mobile with Lottie — load JSON animation files, control playback, listen to events, and integrate animations into React, Vue, or vanilla JS apps. Use when tasks involve adding motion graphics, animated icons, loading indicators, or micro-interactions exported from After Effects or other animation tools."
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "skills.sh",
      "repository": "https://github.com/terminalskills/skills",
      "path": "skills/lottie/SKILL.md",
      "ref": "HEAD",
      "url": "https://github.com/terminalskills/skills/blob/HEAD/skills/lottie/SKILL.md",
      "key": "terminalskills/skills/skills/lottie/SKILL.md"
    },
    "compatibility": "Browser or React Native",
    "license": "Apache-2.0"
  },
  "instructions": "# Lottie\n\nRender After Effects animations exported as JSON. Lightweight, scalable, and interactive.\n\n## Setup\n\n```bash\n# Install lottie-web for vanilla JS/TS projects.\nnpm install lottie-web\n```\n\n## Basic Playback\n\n```typescript\n// src/lottie/player.ts — Load and play a Lottie animation in a DOM container.\n// The animation JSON is typically exported from After Effects via Bodymovin.\nimport lottie, { AnimationItem } from \"lottie-web\";\n\nexport function playAnimation(\n  container: HTMLElement,\n  animationData: object\n): AnimationItem {\n  return lottie.loadAnimation({\n    container,\n    renderer: ",
  "cost": {
    "context_tokens": 1094
  }
}

Fetch it by URL: GET /api/v1/registry/terminalskills-skills-lottie/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.