How would one go about making a progress bar in html/css/javascript. I don\'t really want to use Flash. Something along the lines of what can be found here: http://dustincur
I was writing up an answer to a similar question that got deleted, so I'm posting it here in case it's of use to anyone.
The markup can be dropped in anywhere and takes up 50px of vertical real estate even when hidden. (To have it take up no vertical space and instead overlay the top 50px, we can just give the progressContainerDiv
absolute positioning (inside any positioned element) and style the display
property instead of the visible
property.)
The general structure is based on code presented in this Geeks for Geeks article.
const
progressContainerDiv = document.getElementById("progressContainerDiv");
progressShownDiv = document.getElementById("progressShownDiv");
let
progress = 0,
percentageIncrease = 10;
function animateProgress(){
progressContainerDiv.style.visibility = "visible";
const repeater = setInterval(increaseRepeatedly, 100);
function increaseRepeatedly(){
if(progress >= 100){
clearInterval(repeater);
progressContainerDiv.style.visibility = "hidden";
progressNumberSpan.innerHTML = "";
progress = 1;
}
else{
progress = Math.min(100, progress + percentageIncrease);
progressShownDiv.style.width = progress + "%";
progressNumberSpan.innerHTML = progress + "%";
}
}
}
#progressContainerDiv{
visibility: hidden;
height: 40px;
margin: 5px;
}
#progressBackgroundDiv {
width: 50%;
margin-left: 24%;
background-color: #ffffd;
}
#progressShownDiv {
width: 1%;
height: 20px;
background-color: #4CAF50;
}
#progressNumberSpan{
margin: 0 auto;
}