如何使用setInterval和ClearInterval?function doKeyDown(event) {
switch (event.keyCode) {
case 32:
/* Space bar was pressed */
if (x == 4) {
setInterval(drawAll, 20);
}
else {
setInterval(drawAll, 20);
x += dx;
}
break;
}}大家好,我想打电话drawAll()一次不创建环路那个电话drawAll一次又一次,是使用递归方法还是应该使用递归方法?clearInterval?也请告诉我用clearInterval?谢谢:)
3 回答
泛舟湖上清波郎朗
TA贡献1818条经验 获得超3个赞
setInterval
clearInterval
var handle = setInterval(drawAll, 20);// When you want to cancel it:clearInterval(handle);handle = 0; // I just do this so I know I've cleared the interval
0
0
setTimeout
clearTimeout
setTimeout(drawAll, 20);
HUX布斯
TA贡献1876条经验 获得超6个赞
间隙
var interval = setInterval(doStuff, 2000); // 2000 ms = start after 2sec function doStuff() { alert('this is a 2 second warning'); clearInterval(interval);}
添加回答
举报
0/150
提交
取消