Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's 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 it's URL and the proper URL extention.

+ 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

Save Automatically?

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-us">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width">
    <title>Sequencing animations</title>
    <script type="text/javascript" src="main.js" defer></script>
    <link href="style.css"rel="stylesheet">
  </head>

  <body>

    <div id="alice-container">
      <img id="alice1"  src="https://raw.githubusercontent.com/mdn/learning-area/main/javascript/asynchronous/sequencing-animations/start/alice.svg" role="img" alt="silhouette of crouching long haired character in dress and short boots">
      <img id="alice2"  src="https://raw.githubusercontent.com/mdn/learning-area/main/javascript/asynchronous/sequencing-animations/start/alice.svg" role="img" alt="silhouette of crouching long haired character in dress and short boots">
      <img id="alice3"  src="https://raw.githubusercontent.com/mdn/learning-area/main/javascript/asynchronous/sequencing-animations/start/alice.svg" role="img" alt="silhouette of crouching long haired character in dress and short boots">
    </div>

  </body>

</html>

              
            
!

CSS

              
                body {
  background: #6c373f;
  display: flex;
  justify-content: center;
}

#alice-container {
  width: 90vh;
  display: grid;
  place-items: center;
  grid-template-areas:
    "a1 . ."
    ". a2 ."
    ". . a3";
}

#alice1 {
  grid-area: a1;
}

#alice2 {
  grid-area: a2;
}

#alice3 {
  grid-area: a3;
}

              
            
!

JS

              
                const aliceTumbling = [
  { transform: 'rotate(0) scale(1)' },
  { transform: 'rotate(360deg) scale(0)' }
];

const aliceTiming = {
  duration: 2000,
  iterations: 1,
  fill: 'forwards'
}

const alice1 = document.querySelector("#alice1");
const alice2 = document.querySelector("#alice2");
const alice3 = document.querySelector("#alice3");

const alice1AnimationObj = alice1.animate(aliceTumbling, aliceTiming);
const { finished: alice1Finished } = alice1AnimationObj;

// Promise version of the "callback hell" problem
/* alice1Finished.then(() => {
  console.log('Alice1 has finished its animation');
  const alice2AnimationObj = alice2.animate(aliceTumbling, aliceTiming);
  const { finished: alice2Finished } = alice2AnimationObj;
  alice2Finished.then(() => {
    console.log('Alice2 has finished its animation');
    const alice3AnimationObj = alice3.animate(aliceTumbling, aliceTiming);
    const { finished: alice3Finished } = alice3AnimationObj;
    alice3Finished.then(() => {
      console.log('Alice3 has finished its animation');
      console.log('All animations complete!');
    })
  })
}) */

// Promise chaining
alice1Finished
  .then(() => {
    return alice2.animate(aliceTumbling, aliceTiming).finished;
  })
  .then(() => {
    return alice3.animate(aliceTumbling, aliceTiming).finished;
  })
  .then(() => console.log('All animations complete!'));

// Async/await syntax
/* async function goAliceGo() {
  try {
    await alice1Finished;
    const alice2AnimationObj = alice2.animate(aliceTumbling, aliceTiming);
    await alice2AnimationObj.finished;
    const alice3AnimationObj = alice3.animate(aliceTumbling, aliceTiming);
    await alice3AnimationObj.finished;
    console.log('All animations complete!');
  }
  catch (error) {
    console.error(`Something went wrong with the animations: ${error}`)
  }
} */

// goAliceGo();
              
            
!
999px

Console