除了在每个步骤上重绘整个圆圈之外,还有其他解决方法吗?
简而言之,不,如果您希望它可以跨浏览器工作并且使用半透明颜色看起来不错,则不会。
这意味着,修改您的代码以清除每次绘制并消除起始角度步骤:http: //jsfiddle.net/pcNzb/10/
看到两个 !!! 标记的评论:
var interval=setInterval(function(){
if(stop) {
return;
}
// Log current state
log.prepend('<tr><td>We are at PIradians '+moveToRad/Math.PI+'</td><td>, radians '+moveToRad+'</td><td>, degrees '+Math.round(moveToRad*180/Math.PI)+'</td></tr>');
// console.log('We are at PIradians',moveToRad/Math.PI,', radians',moveToRad,', degrees',Math.round(moveToRad*180/Math.PI));
// Clear after full cycle
if(moveToRad>=fullCycle){
cycle();
}
clear(); // !!! gotta clear!
// Create arc
// 0.01 fix offset, to remove that gap between arc parts
ctx.arc(x(),y(),radius,-moveFromRad,-moveToRad,antiClockwise);
// Draw arc line
ctx.stroke();
// Recalculate text width
txtsizes=ctx.measureText(cycles);
// Text width/2 and font-size / 3 to ~center the text in circle
ctx.fillText(cycles, x(-txtsizes.width/2), y(font_height/3));
// Don't redraw full arc from the start, draw from the last point
//moveFromRad+=step; // !!! no more me!
// Increment radian for the next step
moveToRad+=step;
ctx.beginPath();
},period);