<div id="progressbar">
<div id="loading"></div>
<div id="value">0%</div>
</div>
<br />
<button onclick="isProgressing()">Click Me</button>
#progressbar {
position: relative;
display: flex;
align-items: center;
justify-content: flex-start;
width: 100%;
background: lightgrey;
}
#loading {
width: 1%;
height: 25px;
background: green;
}
#value {
position: absolute;
right: 10px;
}
var i = 0;
function isProgressing() {
if (i == 0) {
i = 1;
var elem = document.getElementById("loading");
var val = document.getElementById("value");
var width = 0;
var id = setInterval(frame, 1);
function frame() {
if (width >= 100) {
clearInterval(id);
i = 0;
} else {
width++;
elem.style.width = width + "%";
val.innerHTML = width + "%";
}
}
}
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.