How can I stop setInterval and then resume from the same place?
Example:
start ---> 1,2,3,4,5 .... ---> stop ---> start ---> 6,7,8 ...
index.html
<div onclick=start()>start</div>
<div onclick=stop()>stop</div>
index.js
let refreshInterval = null;
start() {
var i = 0;
refreshInterval = setInterval(function() {
console.log(i);
i++;
}, 1000);
}
stop() {
???????
}
You need a global variable
i
and for stopping aclearInterval
.