Javascript setTimeout function

前端 未结 6 1230
长发绾君心
长发绾君心 2021-01-14 11:56

I am calling this function

function drawLayers() {

    //setTimeout(drawBlueSky,500);
    //setTimeout(drawCircle1,1250);
    setTimeout(drawMoon,800);
             


        
6条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-14 12:50

    You can define a var corresponding to your setTimeout and then clear it if you want to cancel the timeout.
    For instance:

    // set a timeout
    timer = setTimeout("testtimeout()",3000);   
    
    // clear the timeout
    clearTimeout(timer);
    

    You can wrap all your timeouts within an array and loop over the array to cancel every timeout

    [EDIT] seems like Exelian's answer is quite cleaner and more adapted to your code

提交回复
热议问题