JSFiddle - React, Tailwind, and code Playground
by Tech Savant
HTML
<div class="loading-bar">
<div class="bar"><div class="bar-inner"></div></div>
<div class="bar"><div class="bar-inner"></div></div>
</div>
SCSS
.loading-bar {
clear: both;
height: 12px;
width: 100%;
position: relative;
.bar {
margin: 0 auto;
height: 12px;
position: absolute;
top: 0;
left: 0;
width: 100%;
text-align: center;
z-index: 0;
.bar-inner {
margin: 0 auto;
width: 0;
height: 12px;
-webkit-animation-name: loadbars;
-webkit-animation-duration: 1s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: ease-in-out;
}
&:nth-child(1) .bar-inner {
background: gray;
}
&:nth-child(2) .bar-inner {
background: blue;
-webkit-animation-delay: 0.5s;
}
}
}
@-webkit-keyframes loadbars {
0% { width: 0; }
50% { width: 100%; }
100% { width: 100%; }
}
JavaScript
var bars = $(".bar-inner");
var zindex = 1;
var listener = function () {
zindex++;
$(this).parent().css("z-index", zindex);
};
bars.on("webkitAnimationIteration", listener);