0
对于决定回答这个问题的人,我突然遇到了一个小问题。
我尝试做以下:Javascript set/clearInterval assist
创建
var intrvl; //for interval
function strt() {
//and set interval
intrvl = setInterval(writeT,3000);
}
function writeT() {
//do something here as the interval runs
checkIf(); //check for the mouse down
}
function checkIf() {
//here goes the code that checks if mouse is down and if it is
//then I call another function that begins other useful process
//I tried
if (c.addEventListener('click')) { //c is my canvas
clearInterval(intrvl); //guess clearing the interval yee?
//and then calling the function I want to call
startDoing();
}
}
我要等待,直到有人点击画布上使用间隔,然后运行所需的功能。
但是,无论何时点击画布,函数startDoing()
都会运行,但与运行它相比,运行速度太快而没有这一切。
如何让它工作?正如我想要的那样,首先创建的时间间隔不存在,只有startDoing()
运行。