css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <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);
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................