Walrus
Walrus

Reputation: 20444

Repeat JQuery .each() function infinite number of times

How would one make this each function keep on performing forever.

$('.featuedbanner img').each(function(){
    $(this).delay(featlay).animate({opacity: 1,  leaveTransforms:true}, {duration:2000, queue:true});
    featlay += 6000;
    $(this).delay(featlay).animate({opacity: 0,  leaveTransforms:true}, {duration:2000, queue:true});
});

That is to make this an infinite loop

Upvotes: 2

Views: 2349

Answers (2)

Jakub Konecki
Jakub Konecki

Reputation: 46008

var loop = function(){
    var featlay = 0;
    $('.featuedbanner img').each(function(){
            $(this).delay(featlay).animate({opacity: 1,  leaveTransforms:true}, {duration:2000, queue:true});
            featlay += 6000;
            $(this).delay(featlay).animate({opacity: 0,  leaveTransforms:true}, {duration:2000, queue:true});
        });

    setTimeout(loop, 0);
};

loop();

Upvotes: 1

Wasim Karani
Wasim Karani

Reputation: 8886

You will have to do some thing like this to achieve the following

Jsfiddle Example1

Also

Jsfiddle Example2

Upvotes: 3

Related Questions