JSFiddle - React, Tailwind, and code Playground

by princeofabyss

HTML

<div id='progressbar'></div>

CSS

.progressbar {
  width: 100%;
  margin: 25px auto;
  border: solid 1px black;
}

.progressbar .inner {
  height: 25px;
  animation: progressbar-countdown;
  animation-iteration-count: 1;
  animation-fill-mode: forwards;
  animation-play-state: paused;
  animation-timing-function: linear;
}

@keyframes progressbar-countdown {
  0% {
    width: 100%;
    background: blue;
  }

  100% {
    width: 0%;
    background: red;
  }
}

JavaScript

function createProgressbar(id, duration, delay, callback) {
  var progressbar = document.getElementById(id);
  progressbar.className = 'progressbar';

  var progressbarinner = document.createElement('div');
  progressbarinner.className = 'inner';

  progressbarinner.style.animationDuration = duration;
  progressbarinner.style.animationDelay = delay;

  if (typeof(callback) === 'function') {
    progressbarinner.addEventListener('animationend', callback);
  }

  progressbar.appendChild(progressbarinner);
  progressbarinner.style.animationPlayState = 'running';
}

addEventListener('load', function() {
  createProgressbar('progressbar', '180s', '-20s', function() {
    alert('Progressbar finished...');
  });
});