views:

338

answers:

1

Hey,

I have a jQuery timer going and it seems to mess up after 2 cycles: treethink.treethink.net/backup

Right now, on different timers it will retract the news ticker and change which div is showing then pop it out again. After a couple cycles, which you can see in the link above, some stay longer and then overlap and it becomes a mess. I'm not sure why this is happening...

Here is my code:

/* 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});

        });

    });

Thanks,

Wade

+2  A: 

Let's ignore all the oneTimes since they're not going to mess you up.

$("#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});
    });
});

You have 4 objects: ticker, the container, and 3 messages.

The container's behavior is this (approximately, and not counting the first pull-out): Every 21.5 seconds, hide for 1.5 seconds and then slide back out. Fine, this isn't the source of the problem, the 3 message timers are the problem.

This is the message behavior in intervals:

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

Edit I had my numbers wrong for the first ticker interval time, but I still think the idea is the same. Eventually, the times overlap.

Jonathon
Thanks Jon. How can I clean this up?I thought I did the math properly. Basically I want each one to "show" a div, wait 2 seconds, come out for 20 seconds, retract, change div to the next and repeat that cycle. How can I write the code or timers pull this off?Thanks
Wade D Ouellet
I'm not sure this timer system will work, I am using a new method but there's an issue that comes with that as well which I'm going to post a new question for.I'll toss you a check mark though because your graph for sure helped me understand the problem.Thanks.
Wade D Ouellet
@Wade I had the first time wrong, but I still think that's what's happening.
Jonathon
@Wade I was working on a different method, but if you're trying something else I guess it's moot.
Jonathon
Thanks for your help but I discovered a method that ended up working out much better. Basically the div switches aren't on timers and are just part of the cycle and it picks a random one to start then cycles through them. Much better than all these timers doing their own thing.
Wade D Ouellet