I have a setInterval function and isRunning variable. How do I stop setInterval when isRunning gets set to false?
Thanks.
答案 0 :(得分:2)
See the comments inline:
var isRunning = true; // Define it outside so that can be accessed inside setInterval
var interval = setInterval(function() {
// Your code here
// Check if variable is false, then clear interval
if (isRunning == false) {
clearInterval(interval);
}
}, 100);