我試圖停止/清除間隔,但我收到錯誤。下面如何停止/清除間隔
代碼:
function play(){
function sequencePlayMode() {
var arg1;//some arguments
var arg2;//some arguments
changeBG(arg1,arg2);//here is function that changes the background
}
var time = 5000;
var timer = setInterval(sequencePlayMode, time);//this starts the interval and animation
}
function stop(){
var stopPlay = clearInterval(sequencePlayMode);//here i'm getting error "sequencePlayMode is not defined"
}
$("#startAnimation").click(function(){
play();
});
$("#stopAnimation").click(function(){
stop();
});
有人可以幫助我嗎?
clearInterval(timer);試試這個 – laaposto
可能的重複[停止JavaScript中的setInterval調用](http://stackoverflow.com/questions/109086/stop-setinterval-call-in-javascript) – plalx