JSFiddle - React, Tailwind, and code Playground
HTML
<div id="wrap">
<div id="progress_bar_wrap"></div>
<div id="buttons">
<input type="button" id="set_25" value="25%" />
<input type="button" id="set_50" value="50%" />
<input type="button" id="set_75" value="75%" />
<input type="button" id="from_0_to_100" value="0% - 100%" />
</div>
</div>
CSS
html, body {margin: 50px; padding: 0px; font-family: Tahoma;}
body {background: #fff;}
wrap {margin: 100px;}
#buttons {margin: 10px 0 0 0;}
#progress_bar_wrap {width: 300px; height: 30px; border: solid 1px #222;}
JavaScript
function progress_bar(container){
var bar = document.createElement('div');
var text = document.createElement('div');
bar.style.width = '0xp';
bar.style.height = '100%';
bar.style.background = '#eef';
container.appendChild(bar);
text.style.marginTop = '-25px';
text.style.textAlign = 'center';
text.style.color = '#111';
text.style.textSize = '15px';
text.appendChild(document.createTextNode('0%'));
container.appendChild(text);
this.set_percentage = function(percentage){
bar.style.width = percentage + "%";
text.removeChild(text.firstChild);
text.appendChild(document.createTextNode(percentage + '%'));
}
}
var bar = new progress_bar(document.getElementById('progress_bar_wrap'));
document.getElementById('set_25').onclick = function(){
bar.set_percentage(25);
}
document.getElementById('set_50').onclick = function(){
bar.set_percentage(50);
}
document.getElementById('set_75').onclick = function(){
bar.set_percentage(75);
}
document.getElementById('from_0_to_100').onclick = function(){
var i = 0;
var interval = window.setInterval(function(){
if (i >= 100){
window.clearInterval(interval);
}
bar.set_percentage(i++);
}, 50);
}