JSFiddle - React, Tailwind, and code Playground

by Brett Gaynor

HTML

<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>My stepped progress bar</title>
    <link href="style.css" type="text/css" rel="stylesheet" />
    <link href="fonts.css" type="text/css" rel="stylesheet" />
    <!-- Web Animation API polyfill-->
    <script src="https://rawgit.com/web-animations/web-animations-js/master/web-animations.min.js"></script>
  </head>

  <body>
    <section>
      <div class="progress__container">

        <div class="progress__bar">
          <div id="progress__fill" class="step1"></div>
          <div class="circ__container">
            <div class="circ" id="circ__1"></div>
            <div class="circ" id="circ__2"></div>
            <div class="circ" id="circ__3"></div>
            <div class="circ" id="circ__4"></div>
          </div>




          <div id="progress__dot" class="prog__1"></div>
        </div>
        <div class="backBar"></div>
        <div class="flexrow">

          <span class="stepName tab-1">Account</span>
          <span class="stepName tab-2">Frequency</span>
          <span class="stepName tab-3">Amount</span>
          <span class="stepName tab-4">Taxes</span>
        </div>
        <div class="button__container">
          <button class="buttonStep" id="back">Back</button>
          <button class="buttonStep is-active" id="next">Next</button>
        </div>
      </div>

    </section>
  </body>

</html>

CSS

/* General Styles */
body {
  font-family: Arial, helvetica, sans-serif;
}



/* Slider Bar Animation */
#progress__fill {
  height: 2px;
  position: absolute;
  top: 7px;
  left: 0;
  background-color: darkred;
  width: 1px;
}

#progress__dot {
  background-color: darkred;
  color: #fff;
  border-radius: 50%;
  height: 8px;
  width: 8px;
  position: absolute;
  text-align: center;
  line-height: 8px;
  padding: 6px;
  top: 0;
  font-size: 12px;


}


/* Static Bar Elements */
.progress__container {
  width: 600px;
  margin: 20px auto;
  position: relative;

}

.backBar {
  height: 2px;
  width: 96%;
  position: absolute;
  top: 7px;
  left: 2%;
  background-color: lightgrey;
}

.progress__bar {
  z-index: 100;
  position: relative;
  width: 96%;
  margin: 0 auto;
}

.circ {
  background-color: #fff;
  border: 2px solid lightgrey;
  border-radius: 50%;
  height: 8px;
  width: 8px;
  display: inline-block;
  position: absolute;

}

.hide {
  visibility: hidden
}

.flexrow {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}

.circ__container {
  padding-top: 3px;
}

.flexrow {
  margin-top: 20px;
}

.stepName {
  font-size: 12px;
  text-align: center;
}

.stepName:first-child {
  text-align: left;
}

.stepName:last-child {
  text-align: right;
}

.stepName.bold {
  font-weight: 600;
}


/* Buttons */
.button__container {
  padding-top: 100px;
}

.buttonStep {
  background: grey;
  color: #fff;
  padding: 10px 25px;
  border-radius: 10px;
  font-size: 16px;
}

#back {
  float: left;
}

#next {
  float: right;
}

.is-active {
  background: darkred;
}

JavaScript

// give a starting value for the transformation
var slideBarWidth = 0,
  slideBarScalePoint = 0,
  currentStep = 1,
  dot = document.getElementById('progress__dot'),
  boxWidth = dot.parentElement.offsetWidth;

// insert the current step number into the progress dot
dot.innerHTML = currentStep;

// place the background dots on the bar
for (var x = 1; x < 5; x++) {
  document.getElementById('circ__' + x).setAttribute('style', 'left: ' + ((boxWidth / 3) * (x - 1)) + 'px');
  if (x == 4) {
    document.getElementById('circ__' + x).setAttribute('style', 'left: ' + (((boxWidth / 3) * (x - 1)) - document.getElementById('circ__' + x).offsetWidth) + 'px');
  }
}

// define the timing for progress dot
var dotTiming = {
  duration: 500,
  fill: "both",
  easing: 'ease-in-out'
}
// define the timing for sliding bar
var barTiming = {
  duration: 500,
  fill: "both",
  easing: 'ease-in-out'
}
var passedTiming = {
  fill: "both"
}

// make the first step name bold
document.getElementsByClassName('tab-' + currentStep)[0].classList.add('bold');





// on click fire the animation
document.getElementById('next').addEventListener('click', function() {
  // make sure the slider does not go further than it should
  if (currentStep > 3) {
    return;
  }



  // define the keyframes for the progress dot
  if (currentStep == 3) {

    var moveDot = [{
        transform: 'translateX(' + ((boxWidth / 3) * (currentStep - 1)) + 'px)'
      },
      {
        transform: 'translateX(' + (((boxWidth / 3) * (currentStep)) - dot.offsetWidth) + 'px)'
      }

    ];
  } else {
    var moveDot = [{
        transform: 'translateX(' + ((boxWidth / 3) * (currentStep - 1)) + 'px)'
      },
      {
        transform: 'translateX(' + ((boxWidth / 3) * (currentStep)) + 'px)'
      },

    ];
  }


  // define the keyframes for the sliding bar
  var slideBar = [{
      transform: 'scaleX(' + ((boxWidth / 3) * (currentStep - 1)) + ')',
      transformOrigin: 'left'
    },
    {
      transform: 'scaleX('...