Home » How to » How to create a Progress Bar using javascript

How to create a Progress Bar using javascript

Posted by: admin October 30, 2017 Leave a comment

We will learn how to use JavaScript and a simple css style to create a Progress Bar, and now you can follow the tutorial step by step to achieve.

Step 1:

Add HTML:

<div id=”myProgress”>
<div id=”myBar”></div>
</div>

Setp 2:

Add CSS:

#myProgress {
width: 100%;
background-color: grey;
}
#myBar {
width: 1%;
height: 30px;
background-color: green;
}

Setp 2:

Add JS:

function 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 + ‘%’;
}
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *