Aperture UI
Content development

Lottie

Playing Lottie JSON animations with the lottie-player element. Attributes, sizing, cost and what the rlottie renderer does not support.

Aperture UI plays Lottie animations (the JSON that Bodymovin exports from After Effects) with rlottie. The library is built into every configuration, including the PartialCore builds that the SDK packages use, so no extra module is needed.

Use it

<lottie-player src="animations/victory.json" width="200" height="200" autoplay loop></lottie-player>

A plain image works too. An <img> whose src ends in .json plays as a looping animation at its normal speed:

<img src="animations/spinner.json" width="48" height="48">

The src resolves against the document and the file is read through IAPCFileSystem, so a title that serves its assets from an archive can play Lottie from it. A path that escapes the allowed roots does not load. See File system.

Attributes

AttributeEffect
srcThe animation JSON. Changing it loads a new animation.
width, heightThe size the animation is rasterized at. Set one and the other follows the animation's aspect ratio. Set neither and the animation's own size is used.
autoplayPlays from the start. It is on unless the value is "false".
loopRepeats. It is on unless the value is "false".
speedA positive number that scales playback speed. The default is 1.

The engine reads these attributes when it creates the player, which happens on first display and again whenever src or the size changes. Changing loop, autoplay or speed on a player that is already running does nothing. A player created with autoplay="false" stays on its first frame until the engine builds it again, which happens when you change src or the size, or recreate the element.

There is no JavaScript API for the player: no play(), pause() or seek(). Control a Lottie animation only through the attributes above, or remove and recreate the element.

What it costs

  • Frames are drawn on the CPU. rlottie renders each frame into a bitmap that is uploaded to the GPU as a texture, as for canvas and SVG. A new frame is rendered only when the animation moves to a different frame.
  • Each new frame repaints the views. When a player renders a frame, the engine marks every view as needing a new command list. Many players, or a large one, keep a view repainting.
  • A hidden player keeps running. Once a player has been displayed, the engine advances it until its element is destroyed, even if you later hide the element with display: none. Remove the element from the DOM when you no longer need the animation.
  • Size matters. A larger bitmap costs more to render and to upload. Use the smallest width and height that look right.
  • A malformed file with an invalid duration or frame rate is shown as its first frame, and the engine logs a warning.

For a looping decoration, Lottie is a good choice over video: it needs no codec and is small. For a simple effect such as a fade or a spin, CSS is cheaper still.

What rlottie does not render

The renderer is the vendored rlottie library, and the animation has to stay inside what it supports. The library's own feature list says it does not support:

  • text layers,
  • After Effects expressions,
  • merge paths,
  • layer effects such as fill, stroke, tint and tritone,
  • skew,
  • some mask modes (lighten, darken, difference), mask expansion and mask feather.

It does support shapes, strokes, gradients, trim paths, masks, mattes, precompositions, images and time remapping. Export your animation with the features rlottie handles, and check it in the engine, not only in a Lottie viewer.

Tests

The test corpus has one Lottie page. It checks that the <lottie-player> element is laid out with the right box. Chrome has no built-in Lottie player, so the animation itself has nothing to be compared with. Check the look of each animation on your target.

On this page