Grow your CSS skills. Land your dream job.

jQuery setTimeout() Won’t Repeat?

  • # January 10, 2010 at 9:26 pm

    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)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".