JSFiddle - React, Tailwind, and code Playground

progress counter

by Jennifer Perrin

HTML

<div id="wrapper">
<div class="loader-container">
  <div class="meter">0</div>
  <span class="runner"></span>
</div>
</div>

CSS

@import url("http://fonts.googleapis.com/css?family=Give+You+Glory|Exo:800");
/* 
SETTINGS
If you need the loader go faster or slower, this is the place to change. Don't forget to update 'time' in the javascript
*/
.loader-container {
  height: 6px;
  width: 600px;
  position: absolute;
  top: 50%;
  left: 50%;
  margin-top: -3px;
  margin-left: -300px;
  background-color: transparent;
  background-image: linear-gradient(left, #5bd8ff, #ff0000);
  box-shadow: inset 0 -2px 2px rgba(0, 0, 0, 0.4);
  border-radius: 3px 0 0 3px;
}
.loader-container:after {
  content: "";
  display: block;
  position: absolute;
  right: 0;
  top: 50%;
  width: 1em;
  height: 1em;
  border-radius: 50%;
  margin-top: -0.5em;
  margin-right: -1em;
  background-image: linear-gradient(top, #000000, #212121);
}
.loader-container.done:after {
  background: Red;
}
.run .runner {
  content: "";
  position: absolute;
  right: 0;
  height: 100%;
  width: 0%;
  background-color: transparent;
  background-image: linear-gradient(top, #000000, #212121);
  animation: loader 10s linear;
}
.meter {
  position: absolute;
  top: 0;
  right: 0;
  font-size: 2em;
  margin-top: .3em;
  color: #ff0000;
  animation: meter 10s linear;
  text-shadow: 0 -1px 0 #333333;
}
.meter:after {
  content: "%";
}
@keyframes loader {
  0% {
    width: 100%;
  }
  100% {
    width: 0%;
  }
}
@keyframes meter {
  0% {
    color: #5bd8ff;
  }
  100% {
    color: #ff0000;
  }
}
/* Decoration */
html,
body {
  height: 100%;
  padding: 0;
  margin: 0;
}
body {
  font-family: 'Exo', sans-serif;
  background: transparent...

JavaScript

var Loader = function () {    
  var loader = document.querySelector('.loader-container'),
      meter = document.querySelector('.meter'),
      k, i = 1,
      counter = function () {
        if (i <= 80) {   
          meter.innerHTML = i.toString();
          i++;
        } else {
          window.clearInterval(k);
        }
      };

	return {
  	init: function (options) {
      options = options || {};
      var time = options.time ? options.time : 0,
	        interval = time/80;
      
    	loader.classList.add('run');
      k = window.setInterval(counter, interval); 
      setTimeout(function () {        
      	loader.classList.add('done');
      }, time);
    },
  }
}();

Loader.init({
  	// If you have changed the @time in CSS, update this number to the corresponding value. Measured in miliseconds.
  	time: 10000
});