JSFiddle - React, Tailwind, and code Playground

by shiqangpan

HTML

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>Loading Animation</title>
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <div class="loading">
      <div class="percent">100%</div>
       <label class="text">Completed!</label>
      <div class="progress-bar">
        <div class="progress"></div>
      </div>
    </div>
    <script src="script.js"></script>
  </body>
</html>

CSS

*{
  margin: 0;
  padding: 0;
}
body{
  background: #151515;
}
.loading{
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
.percent{
  color: #999;
  font-size: 100px;
  font-weight: 400;
  text-align: center;
  margin-bottom: 15px;
}
.progress-bar{
  width: 406px;
  height: 21px;
  background: #111;
  border-radius: 13px;
  padding: 3px;
  box-sizing: border-box;
}
.progress{
  width: 10px;
  height: 15px;
  background: #f60d54;
  border-radius: 13px;
}
.text{
  position: absolute;
  left: 160px;
  color: #fdb5ca;
  font-size: 15px;
  letter-spacing: 1px;
  line-height: 21px;
  display: none;
}
.text-blink{
  animation: animate .7s ease-in-out .1s;
}
@keyframes animate {
  0%{
    opacity: 1;
  }
  50%{
    opacity: 0.2;
  }
  100%{
    opacity: 1;
  }
}

JavaScript

function progress(){
  var percent = document.querySelector('.percent');
  var progress = document.querySelector('.progress');
  var text = document.querySelector('.text');
  var count = 4;
  var per = 16;
  var loading = setInterval(animate, 50);
  function animate(){
    if(count == 100 && per == 400){
      percent.classList.add("text-blink");
      text.style.display = "block";
      clearInterval(loading);
    }else{
      per = per + 4;
      count = count + 1;
      progress.style.width = per + 'px';
      percent.textContent = count + '%';
    }
  }
}
progress();