+ 8

Pausing setInterval()

Is it possible to pause a setInterval() at a click of a button and then continue it again later?

6th Oct 2018, 2:26 AM
Fernando Moceces
Fernando Moceces - avatar
10 ответов
+ 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
6th Oct 2018, 3:35 AM
Calviղ
Calviղ - avatar
+ 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
6th Oct 2018, 2:51 AM
Kirk Schafer
Kirk Schafer - avatar
+ 3
like this, modified from Calviղ's code https://code.sololearn.com/W6QJDUTaffXY
6th Oct 2018, 3:49 AM
Flandre Scarlet
Flandre Scarlet - avatar
+ 3
You guys are so helpful. Thanks 😀
6th Oct 2018, 1:14 PM
Fernando Moceces
Fernando Moceces - avatar
+ 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
7th Oct 2018, 7:55 PM
777
777 - avatar
+ 1
var date = new Date(); alert( . Minutes()); please help me
6th Oct 2018, 6:46 AM
Mohammad bagher
0
I think it is better for you to use a recursive setTimeout function
6th Oct 2018, 2:49 AM
Dejan Dozet
Dejan Dozet - avatar
0
maybe clearInterval(); setTimeout(); setInterval();🤔
6th Oct 2018, 3:39 AM
Flandre Scarlet
Flandre Scarlet - avatar
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
5th Feb 2022, 2:25 PM
Ryugen XD
Ryugen XD - avatar
0
Ahmed Raza Chandio Question What is the interval for this timer? var t = setInterval(func, 10000); Answer 10 seconds
5th Mar 2022, 10:56 AM
Ahmed Raza
Ahmed Raza - avatar