我有setInterval
我希望实时更改它的速度:
var speed = 150;
var repeat = setInterval(loop, speed);
var print = 0;
function loop(){
type();
if (print / 3 === 1) {
clearInterval(repeat);
speed = 1000;
repeat = setInterval(type, speed);
}
if (print / 6 === 1) {
clearInterval(repeat);
speed = 150;
repeat = setInterval(type, speed);
}
}
function type(){
console.log(print);
print++;
}
第一个if
会改变速度但第二个不会改变速度,我该如何解决?