+ 8
Pausing setInterval()
Is it possible to pause a setInterval() at a click of a button and then continue it again later?
10 Réponses
+ 6
<button onclick="tmr=!tmr">Play/Puase</button>
<div id="timer"></div>
<script>
tmr = false, cnt = 0;
setInterval(function(){
if(tmr) timer.innerText = ++cnt;
},10);
</script>
https://code.sololearn.com/W9a76zN1b6jO/?ref=app
+ 3
Not to my knowledge*, but if you want to simulate pausing it people could offer a few+ answers for that.
* and a modal dialog would pause everything
+ 3
like this, modified from Calviղ's code
https://code.sololearn.com/W6QJDUTaffXY
+ 3
You guys are so helpful. Thanks 😀
+ 2
I liked what @Calviղ had answered, but it was actually a pseudo-pausing (as the setInterval() was using an if condition to call the function).
@Fernando Moceces had asked how to pause a time interval, and therefore I made this - https://code.sololearn.com/WucXxBbauJ50/#js
+ 1
var date = new Date();
alert(
.
Minutes());
please help me
0
I think it is better for you to use a recursive setTimeout function
0
maybe clearInterval(); setTimeout(); setInterval();🤔
0
let ps=true;
let c=0;
function pause(){
c+=1;
if(c==1){
ps=false;
}else{
ps=true;
}
if(c>2){
c=0;
}
}
Is Work for me in javascript vanilla
0
Ahmed Raza Chandio
Question
What is the interval for this timer?
var t = setInterval(func, 10000);
Answer
10 seconds