Suppose you have an HTML progress bar:
<div id="progress-bar"> <div id="progress">0%</div> </div>
CSS
#progress-bar { width: 200px; padding: 2px; border: 2px solid #aaa; background: #fff; } #progress { background: #000; color: #fff; overflow: hidden; white-space: nowrap; padding: 5px 0; text-indent: 5px; width: 0%; }
And JavaScript:
var progressElement = document.getElementById('progress') function updateProgress(percentage) { progressElement.style.width = percentage + '%'; progressElement.innerHTML = percentage + '%'; }
You can load it in JavaScript and update the progress bar, for example:
<script>updateProgress(0);</script> <script>updateProgress(0.1);</script> <script>updateProgress(0.2);</script> .. ..
Please note that you cannot put each update in a separate script block, because the browser will try to read the full script before execution, and the progress bar will not work.
source share