JSFiddle - React, Tailwind, and code Playground
by princeofabyss
HTML
<div id='progressbar'></div>
CSS
.progressbar {
width: 100%;
margin: 25px auto;
border: solid 1px black;
background-image: linear-gradient(45deg,
rgba(255, 255, 255, 0.15) 25%,
transparent 25%,
transparent 50%,
rgba(255, 255, 255, 0.15) 50%,
rgba(255, 255, 255, 0.15) 75%,
transparent 75%,
transparent);
}
.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;
}
}
.bars {
background-image: linear-gradient(45deg,
rgba(255, 255, 255, 0.15) 25%,
transparent 25%,
transparent 50%,
rgba(255, 255, 255, 0.15) 50%,
rgba(255, 255, 255, 0.15) 75%,
transparent 75%,
transparent);
background-size: 1rem 1rem;
animation: progress-bar-stripes 1s linear infinite;
width: 100%;
height: 25px;
}
@keyframes progress-bar-stripes {
0% {
background-position: 0 0;
}
100% {
background-position: 2rem 0;
}
}
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);
}
var bars = document.createElement('div');
bars.className = 'bars';
progressbarinner.appendChild(bars);
progressbar.appendChild(progressbarinner);
progressbarinner.style.animationPlayState = 'running';
}
addEventListener('load', function() {
createProgressbar('progressbar', '180s', '-20s', function() {
alert('Progressbar finished...');
});
});