Skip to content

Instantly share code, notes, and snippets.

@OmShiv
Created September 14, 2015 05:36
Show Gist options
  • Save OmShiv/ecd06c47fe5410fb799f to your computer and use it in GitHub Desktop.
Save OmShiv/ecd06c47fe5410fb799f to your computer and use it in GitHub Desktop.
<!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