调用第二个settimeout时清除超时

时间:2013-04-19 05:34:02

标签: javascript jquery html html5

我有5个setoutouts。当第二个被叫时,我想清除第一个。等等... 帮帮我们???

3 个答案:

答案 0 :(得分:1)

尝试类似:

var timeout1 = setTimeout(animate5, 1000);
var timeout2 = setTimeout(function() {
    clearTimeout(timeout1);
    animate4();
}, 11000);
...

答案 1 :(得分:0)

试试这个

 var timeout1 = setTimeout(animate5, 1000);
var timeout2 = setTimeout(function() {
    clearTimeout(timeout1);
    animate4();
}, 11000); 

答案 2 :(得分:0)

尝试

var t5 = setTimeout(animate5, 1000);
var t4 = setTimeout(animate4, 11000);
var t3 = setTimeout(animate3, 21000);
var t2 = setTimeout(function() {
    clearTimeout(t1);
    animate2();
}, 31000);
var t1 = setTimeout(animate1, 41000);