3 回答
TA贡献1828条经验 获得超4个赞
只需添加var start在顶部而不是funct函数内部
完整的JS代码:
var start
var progressCircle_1 = {
procent:89,
startFrom:0,
incrementBy:1,
canvasId:'canvas',
procentId:'procent',
funct: function(){
start = setInterval(function(){draw.call(progressCircle_1)},50);
}
}
var progressCircle_2 = {
procent:59,
startFrom:0,
incrementBy:1,
canvasId:'canvas1',
procentId:'procent1',
funct: function(){
start = setInterval(function(){draw.call(progressCircle_2)},50);
}
}
progressCircle_1.funct();
progressCircle_2.funct();
function draw(){
(this.startFrom<this.procent)?this.startFrom++:clearInterval(start);
var getCanvas = document.getElementById(this.canvasId).getContext('2d');
var getNumber = document.getElementById(this.procentId).innerHTML=this.incrementBy++;
getCanvas.beginPath();
getCanvas.arc(250,250,100,0,0.06283185307179587*this.startFrom);
getCanvas.lineWidth='15';
getCanvas.strokeStyle="white";
getCanvas.lineCap="round";
getCanvas.stroke();
};
添加回答
举报