Javascript HTML5JS增量
我正在使用HTML5画布元素制作一系列圆圈。我使用while循环来增加圆的大小。我试图将它们增加三,但我不确定语法是否正确Javascript HTML5JS增量,javascript,html,Javascript,Html,我正在使用HTML5画布元素制作一系列圆圈。我使用while循环来增加圆的大小。我试图将它们增加三,但我不确定语法是否正确 var cirSize = 2; while (cirSize < 400) { ctx.beginPath(); ctx.strokeStyle="#000000"; ctx.arc(480,480,cirSize++,0,Math.PI*2,true); ctx.str
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)
}
var-cirSize=2;
而(尺寸<400)
{
ctx.beginPath();
ctx.strokeStyle=“#000000”;
arc(480480,cirSize++,0,Math.PI*2,true);
ctx.stroke();
警报(大小)
}
谢谢
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)
}
var-cirSize=2;
而(尺寸<400)
{
ctx.beginPath();
ctx.strokeStyle=“#000000”;
ctx.arc(480480,cirSize,0,数学PI*2,真);
ctx.stroke();
cirSize+=3;//这是更改。
警报(大小)
}
小注:“增量”表示“增加一”“增加三”是毫无意义的。@KendallFrey感谢您的投入,但广义上说,只要您增加一个数量,它就是一个增量。