重复JQuery .each()函数无限次

时间:2011-11-01 13:33:55

标签: jquery

如何让每个功能继续保持永久性。

$('.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});
});

这是为了使这成为一个无限循环

2 个答案:

答案 0 :(得分:3)

你必须做这样的事情才能实现以下目标

Jsfiddle Example1

另外

Jsfiddle Example2

答案 1 :(得分:1)

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();