Jennifer Anthony
Jennifer Anthony

Reputation: 2277

After a while slideshow is stopped ?

why not work true following code and after 5 min stopped?

var x = 0;
var s = 0;

function cicle() {
    if (x < 2) {
        $("#slide").animate({
            "right": "-=893px"
        }, 1500);
        x++;
        s++;
    } else {
        x = 0;
        s++;
        $("#slide").animate({
            "right": "0px"
        }, 1000);
    }
};
var a = setInterval("cicle()", 5000);
if (s == 10) {
    clearInterval(a);
    var a = setInterval("cicle()", 5000);
}

EXAMPLE

Upvotes: 0

Views: 60

Answers (1)

scessor
scessor

Reputation: 16125

Change the first parameter of setInterval to cicle:

var a = setInterval(cicle, 5000);
if (s == 10) {
    clearInterval(a);
    var a = setInterval(cicle, 5000);
}

I hope it solves your problem.

Maybe it would be better to stop the animation before adding a new one:

function cicle() {
    if (x < 2) {
        $("#slide").stop().animate({
            "right": "-=893px"
        }, 1500);
        x++;
        s++;
    } else {
        x = 0;
        s++;
        $("#slide").stop().animate({
            "right": "0px"
        }, 1000);
    }
}

Upvotes: 1

Related Questions