我想做一个非常简单的动画,画一个圆的中心点,然后慢慢画一条线(半径),以一个渐进的圆结束。现在,圆圈部分工作正常,它是行的代码,只是没有按我的意图工作。它只是没有停止。当用户单击画布的特定区域时,一切都会触发。
var lineX = 390;
canvas.addEventListener('click',ProcessClick,false);
function ProcessClick(toi){
var posx = toi.layerX;
var posy = toi.layerY;
if(toi.layerX == undefined || toi.layerY == undefined){
posx = toi.offsetX;
posy = toi.offsetY;
}
if(posx>=315 && posx<=465 && posy>=250 && posy<=300){
ctx.clearRect(300, 60, 180, 180);
lineX = 390;
var interval = setInterval(aniRadio, 50);
}
}//ProcessClick
aniRadio = function(){
if(lineX == 390){
ctx.beginPath();
ctx.arc(390, 150, 4, 0, Math.PI*2, true);
ctx.closePath();
ctx.fillStyle = "black";
ctx.fill();
}
ctx.beginPath();
ctx.moveTo(lineX, 150);
lineX += 5;
ctx.lineTo(lineX, 150);
ctx.closePath();
ctx.stroke();
if(lineX == 465){
clearInterval(interval);//tried calling another function that just contains this line. No luck either.
}
}
我基本上希望间隔在线条到达一个点后自行停止,这样我就可以调用绘制圆的函数。