Is there a way to check if a var is using setInterval()?

前端 未结 6 928
失恋的感觉
失恋的感觉 2020-12-12 16:30

For instance, I am setting an interval like

timer = setInterval(fncName, 1000);

and if i go and do

clearInterval(timer);
         


        
6条回答
  •  旧时难觅i
    2020-12-12 16:47

    I did this like below, My problem was solved. you should set the value like "false", when you clearTimeout the timer.

    var timeer=false;
    ----
    ----
    if(timeer==false)
    {
      starttimer();  
    }
    -----
    -----
    function starttimer()
    {
      timeer_main=setInterval(activefunction, 1000);
      timeer=true;
    }
    
    function pausetimer()
    {
      clearTimeout(timeer_main);
      timeer=false;
    }
    

提交回复
热议问题