2016-12-05 43 views
0

的JavaScript的setInterval不會回到

//change the speed at which the animations are moving 
 
function spd() 
 
{ \t 
 
\t var stuff = document.getElementById("speed"); 
 
\t //if start is enabled 
 
\t //change speed 
 
\t if ((document.getElementById("stop").disabled == false) && (turbochecker == 0)) 
 
\t { 
 
\t \t speed = 50; 
 
\t \t interval = setInterval(function(){next(currani);}, speed); 
 
\t \t turbochecker = 1; 
 
\t } 
 
\t else 
 
\t { 
 
\t \t speed = 250; 
 
\t \t interval = setInterval(function(){next(currani);}, speed); 
 
\t } 
 
}

設置間隔的第二次持續增加由50速度總之,使速度恢復爲250,而不是保持每50增加?

+1

你必須調用'clearInterval()'在預先設定的間隔。 –

回答

0

當你想改變的間隔頻率,你應該先清除它,然後再設置它:

clearInterval(interval)

interval = setInterval(function(){next(currani);}, speed);