Javascript 10秒后停止进度条| CPU%80
我有一个进度条,我在10秒内将其值从0增加到100%。我想在10秒后停止每个进程。但当我取消下面代码的注释时,我的cpu将接近80%-90%。我认为100%后它仍然有效Javascript 10秒后停止进度条| CPU%80,javascript,jquery,progress-bar,cpu-usage,Javascript,Jquery,Progress Bar,Cpu Usage,我有一个进度条,我在10秒内将其值从0增加到100%。我想在10秒后停止每个进程。但当我取消下面代码的注释时,我的cpu将接近80%-90%。我认为100%后它仍然有效 var start = new Date(); var maxTime = 10000; var maxTimeSec = 10; var timeoutVal = Math.floor( maxTime/100 ); animateUpdate(); function updatePr
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;
}
}
var start=newdate();
var maxTime=10000;
var maxTimeSec=10;
var timeoutVal=数学楼层(最大时间/100);
动画更新();
函数updateProgress(百分比,秒){
$('#timerProgress').css(“宽度”,百分比+“%”);
$('timerCountdown')。文本(百分比+“%”秒+秒);
}
函数isLogined(){
userId=$(“#userInfo”).attr(“数据用户”);
userId=parseInt(userId);
var logined=false;
如果(用户ID>0){
登录=真;
}
返回登录;
}
函数animateUpdate(){
var now=新日期();
var timeDiff=now.getTime()-start.getTime();
var sec=maxTimeSec-数学舍入((timeDiff/maxTime)*maxTimeSec);
var perc=数学舍入((timeDiff/maxTime)*100);
//控制台日志(perc);
如果(perc不能复制:
Chrome CPU配置文件显示96%空闲,没有沉重的CPU负载。需要更多信息
var a = "Manditory codeblock so jsfiddle can be linked"
为什么要投否决票?我想问题很清楚。如果我没弄错的话,你的timeoutVal
是100米,你可以根据jQuery的.animate()
来编写动画,这样你的CPU可能仍然很高。