hcx
hcx

Reputation: 13

jquery fade in, fade out loop

I want to create a loop like this,

anim = function () {
    $('.a1').fadeOut(function () {
        $('.b1').fadeIn(function () {
            $('.b1').delay(5000).fadeOut(function () {
                $('.a1').fadeIn(function () {
                    setTimeout(anim, 2000);
                });
            });
        });
    });
};

setTimeout(anim, 2000);

but after one loop .b1 is not fade in again so what could be the problem? or is there a better way to do this?

Upvotes: 0

Views: 716

Answers (1)

Starx
Starx

Reputation: 78971

setTimeout() executes the function once, you are looking for setInterval()

Upvotes: 2

Related Questions