Pen Settings



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


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


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.


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.


                <div id="container">
  <p id="countdown">10</p>

<div id="curtain-left" class="curtain left">
  <h2>countdownAnimation.currentTime<span>(increasing playbackRate)</span></h2>
  <p>Immediately before finish() call<span id="countdown-time"></span></p>
  <p>When countdownAnimation finished<span id="countdown-time2"></span></p>
<div id="curtain-right" class="curtain right">
  <h2>containerAnimation.currentTime <span>(normal playbackRate)</span></h2>
  <p>When countdownAnimation finished<span id="container-time"></span></p>
  <p>When containerAnimation finished<span id="container-time2"></span></p>


                $dark: #333;
$light: #fafafb;
$red: #922;
$green: #226342;
$blue: #224263;
$yellow: #c92;
$orange: #c65;
$greenBlue: #299;
$background: $blue;

* {
  box-sizing: border-box;
html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
body {
  background: $background;
  font-family: Helvetica, sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
#container {
  z-index: 1;
#countdown {
  font-size: 10rem;
  color: $light;
  font-weight: 600;
.curtain {
  position: absolute;
  top: 0;
  bottom: 0;
  height: 100%;
  width: 50%;
  transition: transform .35s ease-out;
  z-index: 0;
  text-align: center;
  color: $light;
  line-height: 1.4;
  &.left {
    left: 0;
    transform: translateY(-100%);
    background-color: $greenBlue;
  &.right {
    right: 0;
    transform: translateY(100%);
    background-color: $green;
  &.closed {
    transform: translateY(0);
  h2 {
    width: 60%;
    display: inline-block;
    font-weight: 600;
    margin-top: 2em;
  p {
    width: 60%;
    display: inline-block;
    margin-top: 2em;
  span {
    display: block;



#container will shrink for as many seconds as is specified in the #countdown element text.

#countdown will pulse via scale and opacity for a unusually long time (500 seconds)

A setInterval changes the countdown value (in addition to increasing the animation’s playbackRate by 15%) every 1000 milliseconds. Once the timer reaches zero it will finish the #countdown animation.

Stats about the currentTime will be shown at the end.

What to expect:
If the timer is set to 1 then currentTime values before #countdown’s animation finishes will match (because playbackRate was not increased).
Any higher starting number will result in a #countdown animation currentTime being higher than the container
var clock = document.getElementById('countdown');
var container = document.getElementById('container');
var curtains = document.querySelectorAll('.curtain');
var time = parseInt(clock.textContent, 10);
var containerTimeBefore = document.getElementById('container-time');
var containerTimeAfter = document.getElementById('container-time2');
var countdownTimeBefore = document.getElementById('countdown-time');
var countdownTimeAfter = document.getElementById('countdown-time2');

var countdownAnimation = clock.animate([
  {opacity: 1, transform: 'scale(.6)'},
  {opacity: .5, transform: 'scale(1)'}
], {
  duration: 500,
  easing: 'linear',
  delay: 0,
  iterations: 1000, //Infinity,
  direction: 'alternate',
  fill: 'forwards'
var containerAnimation = container.animate([
  {transform: 'scale(1)'},
  {transform: 'scale(.2)'}
], {
  duration: time * 1000,
  easing: 'linear',
  delay: 0,
  iterations: 1,
  //fill: 'forwards'

countdownAnimation.onfinish = function() {
  var wrapup = clock.animate([
    {opacity: 0, transform: 'scale(.01) rotate(-10deg)', offset: 0},
    {opacity: 1, transform: 'scale(1.2) rotate(7deg)', offset: .8},
    {opacity: 1, transform: 'scale(1) rotate(0deg)', offset: 1}
  ], {
    duration: 1000,
    easing: 'ease-in-out',
    delay: 0,
    iterations: 1,
    fill: 'forwards'
  wrapup.playbackRate = .6;
  clock.textContent = '0';
  countdownTimeAfter.textContent = countdownAnimation.currentTime;
containerAnimation.onfinish = function() {
  containerTimeAfter.textContent = containerAnimation.currentTime;

var interval = setInterval(function() {
  time = time - 1;
  clock.textContent = time;
  if (time > 0) {
    countdownAnimation.playbackRate = Math.min(countdownAnimation.playbackRate * 1.15, 6);
  } else {
    containerTimeBefore.textContent = containerAnimation.currentTime;
    countdownTimeBefore.textContent = countdownAnimation.currentTime;
}, 1000);