The bar is at rest in 1%, and when you click on the button , it starts moving to 100%. The bar moves at an interval of 10 squires until it reaches 100%.
html Progress Bar
1%
<body>
<h1>html Progress Bar</h1>
<div id="Progress">
<div id="Bar">1%</div>
</div>
<br>
<button onclick="move()">Click</button>
<script>
var i = 0;
function move() {
if (i == 0) {
i = 1;
var elem = document.getElementById("Bar");
var width = 10;
var id = setInterval(frame, 10);
function frame() {
if (width >= 100) {
clearInterval(id);
i = 0;
} else {
width++;
elem.style.width = width + "%";
elem.innerHTML = width + "%";
}
}
}
}
</script>
#Progress {
width: 100%;
background-color: rgb(165, 190, 106);
}
#Bar {
width: 1%;
height: 25px;
background-color: #0f04aa;
text-align: center;
line-height: 25px;
color: white;
}
No comments:
Post a Comment