Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript jQuery setTimeout() Won’t Repeat?

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #27530
    jjshammas
    Member

    I’m trying to build a custom image rotator in jQuery. This is my JavaScript code:

    Code:
    /* Begin Settings */
    var time_int = 1000;
    var container = ‘.images’;
    var object = ‘img’;
    /* End Settings */

    function imageRotator()
    {
    var img_amt = $(container + ” ” + object + “:last-child”).attr(“class”);
    var active = $(container + ” ” + object + “[style!=display:none]”).attr(“class”);
    var next = parseInt(active) + 1;
    $(container + ” ” + object + “.” + active).fadeOut(function(){
    $(container + ” ” + object + “.” + next).fadeIn();
    });
    }

    $(document).ready(function(){
    $(container + ” ” + object).hide();
    $(container + ” ” + object + “.1”).show();
    setTimeout(“imageRotator()”,time_int);
    });

    However, for some reason, the setTimeout at the bottom performs the function once after one second, and then does not continue performing the event after another second. Here’s it in action: http://www.johnshammas.com/demos/imagerotator/

    Can anyone tell me how I can make it repeat?

Viewing 1 post (of 1 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.