The code below demonstrates the issue I am having.
When the the js executes, the progress bar fills, as expected rapidly until the max has been reached.
However, the span#pbarval container is updated very slowly and completes LONG after the progress bar has finished.
$(document).ready(function () {
var max= 20000,
cur=0;
function updatePBar(){
cur++;
jQuery("#pbar").val(cur);
jQuery("#pbarval").html("" + Math.ceil(cur*100/max) + "%");
if (cur<=max){
setTimeout(updatePBar, 10);
}
}
updatePBar();
});
You can see the code executing here: http://jsfiddle.net/EricBrian/fhtp6rpf/
Can somebody explain why this is? How to make it keep up with the progress bar?
Also, I noticed that if I switch tabs, the setTimeout seems to pause. The percentage does not update until I switch back to the tab it is running in.
Thanks! -e