Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<!DOCTYPE html>
<html>
<head>
<title>Progress Bar</title>
</head>
<style type="text/css">
#progress-bar {
background-color: blue;
height: 30px;
border-radius: 2px;
}
</style>
<body>
<div id="container" style="width: 500px;">
<div id="bar-container" style="width: 400px; height:30px; border:1px solid blue; border-radius: 2px; margin: 10% auto;">
<div id="progress-bar" style="width: 0%;">
</div>
</div>
</div>
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function() {
var progressBar = document.getElementById("progress-bar"),
widthPercent = 0,
progressTimeOut = null;
function renderProgresBar() {
widthPercent++;
progressBar.style.width = widthPercent + "%";
window.setTimeout(function() {
if (widthPercent <= 99) {
renderProgresBar();
}
}, 30);
// 30 => for 1%, (3000 / 100)
}
renderProgresBar();
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.