2010-02-05 28 views
1

我有一个jQuery计时器去,似乎搞砸了2个周期后:treethink.treethink.net/backupjQuery的定时器两个周期后搞乱

眼下,对不同的定时器就会缩回新闻股票,并变更为DIV正显示出再再次弹出。经过几个周期后,您可以在上面的链接中看到,有些会停留更长时间,然后重叠并且变得混乱。我不知道为什么会这样......

这里是我的代码:

/* Retracting Ticker */ 

    /* Initially hide all news items */ 

    $('#ticker1').hide(); 
    $('#ticker2').hide(); 
    $('#ticker3').hide(); 

    $("#ticker1").oneTime(1000,function(i) { /* Show 1 once on first pull out */ 

     $('#ticker1').show(); 

    }); 

    $("#ticker1").everyTime(64500,function(i) { /* Hide 3 and show 1 everytime timer gets to certain point */ 

     $('#ticker1').show(); 

    }); 

    $("#ticker1").oneTime(21500,function(i) { /* Hide 1 and show 2 once after first pull out */ 

     $('#ticker1').hide(); 
     $('#ticker2').show(); 

    }); 

    $("#ticker1").everyTime(86000,function(i) { /* Hide 1 and show 2 everytime timer gets to certain point */ 

     $('#ticker1').hide(); 
     $('#ticker2').show(); 

    }); 


    $("#ticker2").oneTime(43000,function(i) { /* Hide 2 and show 3 once after second pull out */ 

     $('#ticker2').hide(); 
     $('#ticker3').show(); 

    }); 

    $("#ticker2").everyTime(107500,function(i) { /* Hide 2 and show 3 everytime timer gets to certain point */ 

     $('#ticker2').hide(); 
     $('#ticker3').show(); 

    }); 

    $("#ticker3").oneTime(64000,function(i) { /* Hide 2 and show 3 once after second pull out */ 

     $('#ticker3').hide(); 

    }); 

    $("#ticker3").everyTime(129000,function(i) { /* Hide 2 and show 3 everytime timer gets to certain point */ 

     $('#ticker3').hide(); 

    }); 

    $("#ticker").oneTime(2000,function(i) { /* Do the first pull out once */ 

     $("#ticker").animate({right: "0"}, {duration: 800 }); 
    }); 

    $("#ticker").oneTime(20000,function(i) { /* Do the first retract once */ 

     $("#ticker").animate({right: "-450"}, {duration: 800}); 

    }); 

    $("#ticker").everyTime(21500,function(i) { /* Everytime timer gets to certain point */ 

     $("#ticker").animate({right: "0"}, {duration: 800}); /* Pull out right away */ 

     $("#ticker").oneTime(20000,function(i) { /* Retract once */ 

      $("#ticker").animate({right: "-450"}, {duration: 800}); 

     }); 

    }); 

感谢,

韦德

+0

我看到它在做什么,但没有花很多时间检查你的计时器,我只能说这只是错误的时机。你能解释什么时候(准确地说)会发生什么? – 2010-02-05 20:17:04

回答

2

让我们忽略所有的oneTime小号,因为他们不要把你搞砸了。

$("#ticker1").everyTime(64500,function(i) { 
    $('#ticker1').show(); 
}); 

$("#ticker1").everyTime(86000,function(i) { 
    $('#ticker1').hide(); 
    $('#ticker2').show(); 
}); 

$("#ticker2").everyTime(107500,function(i) { 
    $('#ticker2').hide(); 
    $('#ticker3').show(); 
}); 

$("#ticker3").everyTime(129000,function(i) { 
    $('#ticker3').hide(); 
}); 

$("#ticker").everyTime(21500,function(i) { 
    $("#ticker").animate({right: "0"}, {duration: 800}); 
    $("#ticker").oneTime(20000,function(i) { 
     $("#ticker").animate({right: "-450"}, {duration: 800}); 
    }); 
}); 

您有4个对象:ticker,容器和3条消息。

容器的行为是这样的(大概,不包括第一次拉出):每21.5秒,隐藏1.5秒,然后滑回去。好吧,这不是问题的根源,3个消息定时器是问题所在。

这是间隔的消息的行为:

ticker show (s) hide (s) 
1   64.5  86 
2   86   107.5 
3   107.5  129 

编辑我有我的号码错误的,第一股票的间隔时间,但我仍然认为这个想法是一样的。最终,时代重叠。

+0

谢谢乔恩。我怎样才能清理它? 我以为我做了正确的数学。基本上我希望每个人“展示”一个div,等待2秒钟,出来20秒,收回,改变div到下一个并重复该周期。我如何编写代码或定时器来解决这个问题? 谢谢 – 2010-02-05 23:24:32

+0

我不确定这个计时器系统是否可以工作,我正在使用一种新的方法,但是还有一个问题伴随着,我将发布一个新的问题。 虽然我会给你一个复选标记,因为你的图肯定帮助我理解了这个问题。 谢谢。 – 2010-02-06 00:54:12

+0

@Wade我第一次错了,但我仍然认为这是发生了什么。 – 2010-02-06 00:58:45