HTML5 Js递增

时间:2012-06-06 14:34:01

标签: javascript html5

我正在使用HTML5 canvas元素制作一系列圆圈。我正在使用while循环来增加圆的大小。我试图将它们增加三,但我不确定正确的语法。

    var cirSize = 2;

    while (cirSize < 400)
      {
        ctx.beginPath();
        ctx.strokeStyle="#000000"; 
        ctx.arc(480,480,cirSize++,0,Math.PI*2,true);
        ctx.stroke();
        alert(cirSize)
      }

由于

1 个答案:

答案 0 :(得分:2)

cirSize++会增加1,++cirSize也会增加。但是有区别。前者将首先返回 cirSize的值,然后然后增量。虽然后者先增加然后返回cirSize

的值
var cirSize = 2;

while (cirSize < 400)
  {
    ctx.beginPath();
    ctx.strokeStyle="#000000"; 
    ctx.arc(480,480,cirSize,0,Math.PI*2,true);
    ctx.stroke();
    cirSize += 3; // here's the change.
    alert(cirSize)
  }