Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>lottiefiles/relottie | color change example</title>
</head>

<body>
  <h1>relottie - color change example</h1>
  <p><a id="lottie-link" target="_blank"><b>Lottie link</b></a></p>
  <div class="container">
    <div class="row">
      <h3>Original Lottie:</h3>
      <canvas id="player"></canvas>
    </div>
    <div class="row">
      <h3>Modified Lottie:</h3>
      <canvas id="player-modified"></canvas>
    </div>
  </div>
</body>

</html>
              
            
!

CSS

              
                body {
  text-align: center !important;
  font-family: monospace;
}

.container {
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
}

canvas {
  width: 300px;
}

              
            
!

JS

              
                import { DotLottie } from "https://esm.sh/@lottiefiles/dotlottie-web";
import { TITLES } from "https://esm.sh/@lottiefiles/last";
import { relottie } from "https://esm.sh/@lottiefiles/relottie";

import { unified } from "https://esm.sh/unified";
import { visit } from "https://esm.sh/unist-util-visit";

// Helpers

const fetchData = async (url) =>
  await fetch(url).then((response) => response.json());

const createPlayer = (data, canvas) =>
  new DotLottie({ data, canvas, autoplay: true, loop: true });

const changeColorRgbaValues = (tree, percentage = 20) => {
  const colorRgbaTitle = TITLES.collection.colorRgba;
  const multiplier = percentage / 100 + 1;

  visit(tree, (node) => {
    const title = node.title;

    if (title !== colorRgbaTitle) return;

    const nodeValue = node.children[0];

    if (!nodeValue) return;

    nodeValue.children.forEach((child) => {
      if (typeof child.value !== "number") return;

      child.value = child.value * multiplier;
    });
  });
};

const getModifiedTree = (originalTree) => {
  const tree = { ...originalTree };

  changeColorRgbaValues(tree);

  return tree;
};

// Constants

const LOTTIE_PATH = {
  json:
    "https://lottie.host/63e43fb7-61be-486f-aef2-622b144f7fc1/2m8UGcP8KR.json",
  source: "https://lottiefiles.com/animations/hiding-lolo-eH80VLpL27"
};

const ELEMENT_ID = {
  player: "player",
  playerModified: "player-modified",
  lottieLink: "lottie-link"
};

// Setup

const lottieJson = await fetchData(LOTTIE_PATH.json);
const lottieJsonStr = JSON.stringify(lottieJson);

const processor = relottie();

// DOM Elements

const playerElm = document.getElementById(ELEMENT_ID.player);
const modifiedPlayerElm = document.getElementById(ELEMENT_ID.playerModified);
const lottieLinkElm = document.getElementById(ELEMENT_ID.lottieLink);

// Run

lottieLinkElm.setAttribute("href", LOTTIE_PATH.source);

createPlayer(lottieJsonStr, playerElm);

const tree = processor.parse(lottieJsonStr);
const modifiedTree = getModifiedTree(tree);
const modifiedLottieJson = processor.stringify(modifiedTree);

createPlayer(modifiedLottieJson, modifiedPlayerElm);

              
            
!
999px

Console