On Dec 1, 4:27 pm, Michel Belleville <michel.bellevi...@gmail.com>
wrote:
> setTimeout(), which is a plain JavaScript function, should be perfect for
> the job then.

... although managing the timeout alongside the next button might get
a little trickier.  You might want to introduce a function which
manages the timeout, especially if there might be more than one of
these on the page.  Something like this, perhaps:

    function createTimer(fn, seconds) {
        var timeout;
        var func = function() {
            clearTimeout(timeout);
            fn();
            timeout = setTimeout(func, (seconds || 60) * 1000);
            return false;
        }
        func();
        return func;
    }

which you might use like this:

    var timer = createTimer(function() {$("#myDiv").load
("random.php");}, 60);
    $("#next").click(timer);

This will handle running every n seconds, restarting the count when
the user chooses "next".

If you need more complex behavior, like a "prev" link or a "stop" it
would have to be somewhat more complicated.

This is plain JavaScript, so we now return you to your regularly
scheduled jQuery discussion.

Cheers,

  -- Scott

Reply via email to