[英]Stop Progress Bar After 10 seconds | CPU % 80
I have a progress bar and I increase its value 0 to 100% in 10 seconds.我有一个进度条,我在 10 秒内将其值从 0 增加到 100%。 I want to stop every process after 10 seconds.我想在 10 秒后停止每个进程。 But when I uncomment below code my cpu going to nearly 80% - 90%.但是当我取消注释下面的代码时,我的 cpu 将接近 80% - 90%。 I think after 100% it still works.我认为在 100% 之后它仍然有效。
var start = new Date();
var maxTime = 10000;
var maxTimeSec = 10;
var timeoutVal = Math.floor( maxTime/100 );
animateUpdate();
function updateProgress(percentage, second) {
$('#timerProgress').css("width", percentage + "%");
$('#timerCountdown').text(percentage + "%" + second + "sec");
}
function isLogined(){
userId = $("#userInfo").attr("data-user") ;
userId = parseInt(userId);
var logined = false;
if(userId > 0){
logined = true;
}
return logined;
}
function animateUpdate() {
var now = new Date();
var timeDiff = now.getTime() - start.getTime();
var sec = maxTimeSec - Math.round( (timeDiff/maxTime) * maxTimeSec );
var perc = Math.round( (timeDiff/maxTime)*100);
//console.log(perc);
if (perc <= 100) {
updateProgress(perc, sec);
setTimeout(animateUpdate, timeoutVal);
}
else{
var bottomDiv = $('#bottomDiv');
bottomDiv.show();
if( isLogined() ){
bottomDiv.text("Congratulations. You're lucky to read this article. We've updated your score.");
}else{
bottomDiv.text("Congratulations. You're lucky to read this article. If want to count your score you must login :)");
}
return true;
}
}
Is there a bug in this code?这段代码有bug吗?
Could not reproduce:无法重现:
https://jsfiddle.net/7jgLLvfz/ https://jsfiddle.net/7jgLLvfz/
Chrome CPU profile shows 96% idle, no heavy CPU load. Chrome CPU 配置文件显示 96% 空闲,没有沉重的 CPU 负载。 Need more information.需要更多信息。
var a = "Manditory codeblock so jsfiddle can be linked"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.