Mark Ku's Blog

Building Lottie animations in Adobe After Effects with JavaScript interaction — Part 1: Dynamic text replacement

Foreword

The company wanted to build a "monkey climbing a tree" mini-game. The trigger was that the existing project already used Lottie animations and the smoothness and feel were great, so I dug deeper into how to build a Lottie mini-game with Adobe After Effects and integrate it with our Vue frontend.

Prerequisites

  1. Install Adobe After Effects
  2. Install the Bodymovin plugin (used to export the Lottie JSON)
  3. Enable "Allow Scripts to Write Files and Access Network" After Effects Edit menu, Preferences and General options highlighted Tick "Allow Scripts to write file and network access". After Effects Preferences, Scripting & Expressions, Allow Scripts to Write Files

Let's start building

First, import a Lottie asset into Adobe After Effects

You can download free Lottie JSON files from lottiefiles.com.

LottieFiles website showing monkey animation and its highlighted download URL
LottieFiles website showing monkey animation and its highlighted download URL

Back in Adobe After Effects, choose Window > Extensions > Bodymovin. After Effects Window menu Extensions Bodymovin highlighted

Click Import Lottie Animation. Bodymovin plugin interface, Import Lottie Animation button highlighted in red

Import the JSON file you just downloaded. Bodymovin plugin importing Lottie animation from URL

Successful import: Bodymovin plugin showing successful Lottie animation import from URL The animation now appears in the asset library: After Effects showing imported monkey animation in project panel

Embedding a text layer for JavaScript to control

Click the horizontal type tool > type some text > "test". Adobe After Effects toolbar with horizontal type tool highlighted

Right-click the text layer > Rename.

After Effects layer context menu with Rename highlighted
After Effects layer context menu with Rename highlighted

An important note: because we'll control this through JavaScript, we use # as a special suffix in the name — characters after # will be converted into an id. Example: test#rate.

After Effects UI showing text layer named test rate
After Effects UI showing text layer named test rate

When the animation is finally rendered to the page, the id is bound to the corresponding DOM element.

SVG code snippet highlighting id= rate attribute in a g element
SVG code snippet highlighting id= rate attribute in a g element

Exporting the Lottie JSON animation

Open Bodymovin via Window > Extensions > Bodymovin and follow the steps below. Bodymovin plugin interface highlighting Lottie JSON export steps

★★★★★ Important ★★★★★ When exporting the Lottie animation, you must uncheck "Glyphs" — i.e. remove the embedded fonts. Otherwise the export keeps failing with "Character could not be created" and the text won't be exported as HTML. Bodymovin settings dialog with Glyphs option selected

We expect to use JavaScript to dynamically replace the text on the layer with the previously assigned id. Here's a Vue example:

撰寫 Example.vue
<template>
  <div>
    <div class="flex">
      <div ref="monkey" />
    </div>
  </div>
</template>
<script>

import loApi from 'lottie-api'
import lottie from 'lottie-web'
import { numberFormat } from '@/utils'

export default {
  components: {

  },
  data() {
    return {
      lottieAnimation: null
    }
  },
  created() {

  },
  mounted() {
    this.lottieAnimation = this.loadLottieAnimation()
    let count = 1
    const that = this

    // 每兩秒去修改 rate 裡面的值
    setInterval(() => {
      count = count + 0.01
      var api = loApi.createAnimationApi(that.lottieAnimation)
      var elements = api.getKeyPath('test#rate').getElements() // 查找對象
      var ele = elements[0]
      const result = '' + numberFormat(count, 2) // 修改改傳入的值必須是字元串不能是數字,否則會失敗
      ele.setText(result)
    }, 2000)
  },
  methods: {
    loadLottieAnimation() {
      return lottie.loadAnimation({
        container: this.$refs.monkey, // 掛在到對應的 DOM 節點
        loop: true,
        animationData: require('@/assets/lottie/monkey.json'),
        autoplay: true
      })
    }
  }
}
</script>

Result

Lottie monkey animation in browser with dynamic text 3.99
Lottie monkey animation in browser with dynamic text 3.99

Demo video link

Wrap-up

Adobe After Effects, combined with the Lottie API, lets you build interactive frontend animations with ease. It's particularly handy for mini-games — you get a wide range of events and properties to tune, like playback speed, play count, looping, and completion callbacks.

Next chapter — Building Lottie animations in Adobe After Effects with JavaScript interaction Part 2: Advanced interactions

Author

Mark Ku

擁有 10+ 年經驗的資深軟體工程師,現為 AI 應用 Builder,專注於大型平台架構與簡化複雜系統設計,從電商系統到訂閱與收費平台,結合 AI Agent、AI 整合與自動化開發,打造高效率且可持續演進的產品技術基礎。Read More

Found this useful?

The author's free tools, daily podcasts and newsletter are all here.

Mark Ku · This article is licensed under CC BY 4.0. Credit the author and link back to the original when reusing it.

Comments

Subscribe to Newsletter

Subscribe to get new posts delivered instantly — never miss a tech share.

By submitting, you agree to receive emails. You can anytime.

Popular Posts

View all
Mark Ku
··602

Oracle Cloud Always Free Tier: Linux Host and Static IP for a $0 Cloud Solution

Oracle Cloud Always Free Tier: Linux Host and Static IP for a $0 Cloud Solution
Mark Ku
··490

Say Goodbye to Postman's Fee Trap! A Hands-on Guide to Bruno, the Open-Source Git-Native API Testing Powerhouse.

Say Goodbye to Postman's Fee Trap! A Hands-on Guide to Bruno, the Open-Source Git-Native API Testing Powerhouse.
Mark Ku
··333

A Free, Open-Source, Notion-like Knowledge Base — A Complete Guide to Deploying and Backing Up Outline Wiki

A Free, Open-Source, Notion-like Knowledge Base — A Complete Guide to Deploying and Backing Up Outline Wiki
Mark Ku
··264

Training Your Own AI Voice: Hardware Requirements, Open-Source Model Comparison, and LoRA Fine-Tuning

Training Your Own AI Voice: Hardware Requirements, Open-Source Model Comparison, and LoRA Fine-Tuning
Mark Ku
··221

Building an Efficient API Management Platform: Deploying Kong Gateway from Scratch - Part 1

Building an Efficient API Management Platform: Deploying Kong Gateway from Scratch - Part 1
Mark Ku
··215

Setting Up Samba on Ubuntu to Share Folders with Windows 11

Setting Up Samba on Ubuntu to Share Folders with Windows 11