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

              
                

  
  <div id="bm"> </div>
  
    <div id="btn"> 
      <button id="idle1">default (loop)</button>
      <button id="idle2">idle 2</button>
      <button id="talk1">talk 1 (loop)</button>
      <button id="talk2">talk 2</button>
      <button id="correct1">correct 1</button>
      <button id="correct2">correct 2</button>
      <button id="wrong1">wrong 1</button>
      <button id="wrong2">wrong 2</button>
    </div>
              
            
!

CSS

              
                html,
body {
  background-color: #efefef;
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

#bm {
  margin-left: auto;
  margin-right: auto;
  width: 215pt;
  height: 116pt;
}

button {
  font-size: 14pt;
  position: relative;
  display: inline;
  width: 108pt;
  height: 40pt;
  padding: 5pt 10pt;
  margin: 2pt;
  line-height: 20pt;
  background-color: #50E3C2;
  border-radius: 100pt;
  border: none;
}

button:hover {
  color: white;
  background-color: #41D1BB;
}

button:active {
  background-color: #008575;
}

#btn {
  width: 100%;
  position: absolute;
  bottom: 0;
  left: 10pt;
}
              
            
!

JS

              
                var idle1 = document.getElementById("idle1");
var idle2 = document.getElementById("idle2");
var talk1 = document.getElementById("talk1");
var talk2 = document.getElementById("talk2");
var correct1 = document.getElementById("correct1");
var isLooping = false;
var shareCode = "z4dUPV";

var bm = document.getElementById("bm");
var animData = {
  container: bm,
  renderer: "svg",
  loop: true,
  prerender: false,
  autoplay: false,
  autoloadSegments: false,
  path: "https://assets4.lottiefiles.com/temp/lf20_" + shareCode + ".json"
  //"https://amplify-education.github.io/aqua-sandbox/bodymovin/alyx_keyhole.json"
};
var anim;

anim = bodymovin.loadAnimation(animData);
anim.addEventListener("DOMLoaded", startAnimation);
idle1.onclick = btnIdle1;
idle2.onclick = btnIdle2;
talk1.onclick = btnTalk1;
talk2.onclick = btnTalk2;
correct1.onclick = btnCorrect1;
correct2.onclick = btnCorrect2;
wrong1.onclick = btnWrong1;
wrong2.onclick = btnWrong2;

function btnIdle1() {
  anim.playSegments([1, 45], true);
}
function btnIdle2() {
  if (isLooping) {
    return;
  }
  isLooping = true;
  anim.playSegments([[45, 90],[1, 45]], true);
  anim.addEventListener("loopComplete", setIdle1);
}
function idle2talk() {
  anim.playSegments([91, 97], true);
}
function btnTalk1() {
  anim.playSegments([97, 157], true);
}
function btnTalk2() {
  if (isLooping) {
    return;
  }
  isLooping = true;
  anim.playSegments([[157, 220],[221,228],[1, 45]], true);
  anim.addEventListener("loopComplete", setIdle1);
}
function talk2idle() {
  anim.playSegments([221, 228], true);
}
function btnCorrect1() {
  if (isLooping) {
    return;
  }
  isLooping = true;
  anim.playSegments([[228, 248],[1, 45]], true);
  anim.addEventListener("loopComplete", setIdle1);
}
function btnCorrect2() {
  if (isLooping) {
    return;
  }
  isLooping = true;
  anim.playSegments([[308, 352],[1, 45]], true);
  anim.addEventListener("loopComplete", setIdle1);
}
function btnWrong1() {
  if (isLooping) {
    return;
  }
  isLooping = true;
  anim.playSegments([[248, 275],[1, 45]], true);
  anim.addEventListener("loopComplete", setIdle1);
}

function btnWrong2() {
  if (isLooping) {
    return;
  }
  isLooping = true;
  anim.playSegments([[275, 308],[1, 45]], true);
  anim.addEventListener("loopComplete", setIdle1);
}

function setIdle1() {
 isLooping = false;
 anim.removeEventListener("loopComplete", setIdle1);
}

function startAnimation() {
  btnIdle1();
}

              
            
!
999px

Console