Frist of all let understand. what is progress bar?
The progress bar uses basic markup. There is: a container with computed classes based on the current step: progressClasses. a static background track: progress_bg. a loop that iterates through each step and applies stepClasses based on the current step.
You will get Preview something like this:
Lets Have a look on code:
HTML:
<!DOCTYPE html>
<html>
<head>
<title></title>
<link href="https://fonts.googleapis.com/css?family=Maven+Pro&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
<style>
*{
font-family: 'Maven Pro', sans-serif;
}
#myprogress{
width: 80%;
background: grey;
margin: auto;
}
#mybar{
width: 1%;
background: green;
color: white;
text-align: center;
}
</style>
<body>
<h1 style="text-align: center;"><i class="fa fa-music" aria-hidden="true"></i>Progress Bar using JavaScript <i class="fa fa-music" aria-hidden="true"></i> </h1>
<div id="myprogress">
<div id="mybar">
<span id="incvalue">1%</span>
</div>
</div>
<br> <button onclick="move()">ClickMe</button>
<script>
const move = () => {
var elem = document.getElementById("mybar");
var width = 1;
var id = setInterval(frame, 10)
function frame(){
if(width >= 100){
clearInterval(id);
}else{
width++;
elem.style.width = width + "%";
document.getElementById("incvalue").innerHTML = width + "%";
}
}
}
</script>
</body>
</html>
Output:

Comments
Post a Comment