我正在研究一个 javascript 旋转轮,但我只能通过在 while 方法中放置一个 alert() 来让它运行,如下所示(然后在 Chrome 上单击以忽略连续的消息)。任何帮助或对正在发生的事情的解释将不胜感激。
$(document).ready(function() {
var colors = ["#000000", "#FFFFFF", "#FFFFFF", "#FFFFFF"];
var arc = Math.PI / 2;
var ctx;
var startAngle = 0;
function drawWheel(startAngle) {
var canvas = document.getElementById("wheel");
if (canvas.getContext) { // Checks for browser support
var outerRadius = 200,
innerRadius = 1;
ctx = canvas.getContext("2d");
ctx.strokeStyle = "black";
ctx.lineWidth = 2;
for(var i = 0; i < 4; i++) { // change to support size of wheel
var angle = startAngle + i * arc;
ctx.fillStyle = colors[i];
ctx.beginPath();
ctx.arc(250, 250, outerRadius, angle, angle + arc, false);
ctx.arc(250, 250, innerRadius, angle + arc, angle, true);
ctx.stroke();
ctx.fill();
}
}
}
function clearWheel() {
var canvas = document.getElementById("wheel");
ctx = canvas.getContext("2d");
ctx.clearRect(0,0,500,500);
}
var i = 0;
while (i<=500) {
// alert(i);
drawWheel(i);
i++;
}
});