The code below demonstrates the problem I am facing.
When js is executed, the progress bar fills up, as expected, quickly until the maximum value is reached.
However, the span # pbarval container updates very slowly and exits LONG after the completion of the execution line.
$(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 executable code here: http://jsfiddle.net/EricBrian/fhtp6rpf/
Can someone explain why this is so? How to make it keep up with the progress bar?
Also, I noticed that if I switch tabs, setTimeout seems to pause. The percentage is not updated until I return to the tab in which it is running.
Thank! -e
source
share