Use a counter which increments each time the callback gets executed, and when it reaches your desired number of executions, use clearInterval()
to kill the timer:
var counter = 0;
var i = setInterval(function(){
// do your thing
counter++;
if(counter === 10) {
clearInterval(i);
}
}, 200);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…