1

我有一个 jQuery 计时器,它似乎在 2 个周期后搞砸了:treethink.treethink.net/backup

现在,在不同的计时器上,它会收回新闻代码并更改正在显示的 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});

        });

    });

谢谢,

韦德

4

1 回答 1

2

让我们忽略所有的oneTimes,因为它们不会把你搞砸。

$("#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 个对象:股票代码、容器和 3 条消息。

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

这是间隔的消息行为:

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

编辑我在第一个自动收报机间隔时间内的数字是错误的,但我仍然认为这个想法是一样的。最终,时间重叠。

于 2010-02-05T21:12:29.387 回答