Victorino
Victorino

Reputation: 1641

SlideShow Function

I have a slide show function that is simply changing the background to seven different images.

I've got a variable limit and start index.

It is working fine, but the problem is that I need to call this function all time (often?) and when the index is equal to limit the function stops working. How can I reset the index?

function:

(function indexSlideShow(index) 
{
    var $limit = 7;
    setTimeout(function() 
    {
        $('#eventDetails').fadeTo(800, 1, function()
        {
            $('#eventDetails').css(
            {
                "background" : "url(images/indexImgs/bigBg/" + index + ".jpg) no-repeat",
                "background-position" : "cover"
            })
        }).fadeTo(800, 1);
    }, 4000);

    index++;

    if (index <= $limit-1) 
    {
        setTimeout(function()
        {
            indexSlideShow(index)
        },4000)
    };
})(1); 

Upvotes: 1

Views: 134

Answers (2)

Victorino
Victorino

Reputation: 1641

here is solution of this . may be for some one it be useful

    /* index slide show function */
    (function indexSlideShow(index) {

        var $limit = 7;

            setTimeout(function() {

            $('#eventDetails').fadeTo(800, 1, function(){

            $('#eventDetails').css({

                "background" : "url(images/indexImgs/bigBg/" + index + ".jpg) no-repeat",
                "background-position" : "cover"
            })

            }).fadeTo(800, 1);

        }, 4000);

        index++;         

        if (index == $limit) {

            setTimeout(function(){

                 indexSlideShow(0);

            },4000);

        } else  if (index < $limit) {

            setTimeout(function(){

                indexSlideShow(index);

            },4000);
        }  

    })(1);//end index slide show function

Upvotes: 0

creimers
creimers

Reputation: 5305

You could say that if the limit is reached, the index should be reset before your if (index <= $limit-1) {} statement. Like so:

if (index == $limit-1) {
    index = 0;
} 

setTimeout(function()
    {
        indexSlideShow(index)
    },4000)
};

Upvotes: 1

Related Questions