I have the variable X
X = setInterval(function() { ...
and after a while I gave a stop in this setInterval with the function clearInterval(X)
How do I call this variable to continue the loop after it has been "deleted"?
I have the variable X
X = setInterval(function() { ...
and after a while I gave a stop in this setInterval with the function clearInterval(X)
How do I call this variable to continue the loop after it has been "deleted"?
You can not stop and restart setInterval
. What you can do is:
Defines the function out of setInterval
and then starts / resumes:
function beeper(){
// fazer algo
}
var x = setInterval(beeper, 1000);
// para parar:
clearInterval(x);
// para recomeçar:
x = setInterval(beeper, 1000);
var semaforoVermelho = false;
function beeper(){
if (semaforoVermelho) return;
// fazer algo
}
setInterval(beeper, 1000);
// para pausar:
semaforoVermelho = true;
// para recomeçar:
semaforoVermelho = false;