Jquery each()包括查找干净代码的延迟

Jquery each()包括查找干净代码的延迟,jquery,jquery-animate,Jquery,Jquery Animate,简而言之,我正在寻找一个jQuery循环,它将选择每个具有类的div(一行大约10个小div),然后在每个div上执行一些代码,特别是淡出并在div中包含的图像中,然后暂停并继续,并对下一个div执行相同的操作 此循环同时淡出/淡入所有包含的图像 $('.div_class').each(function() { $(this).children().fadeOut('fast', function() { $(this).fadeIn('slow'); });

简而言之,我正在寻找一个jQuery循环,它将选择每个具有类的div(一行大约10个小div),然后在每个div上执行一些代码,特别是淡出并在div中包含的图像中,然后暂停并继续,并对下一个div执行相同的操作

此循环同时淡出/淡入所有包含的图像

$('.div_class').each(function() {
    $(this).children().fadeOut('fast', function() {
        $(this).fadeIn('slow');
    });
});
我已经研究了jquery函数
delay()
setInterval()
以及本机JavaScript函数
setTimeout()

看来我要么根本无法让它们发挥作用,要么我看到的例子冗长而复杂。有了jquery的魔力,我似乎应该能够在上面的循环中添加很少的代码,使其能够串联工作

如前所述,我正在寻找一个干净简单的示例。

您可以与提供给回调的索引结合使用,如下所示:

$('.div_class').each(function(i) {
    $(this).children().delay(800*i).fadeOut('fast', function() {
        $(this).fadeIn('slow');
    });
});
这将使他们背靠背(快=200+慢=600),如果你想要更多的延迟,只要增加800到你想要的。在上面的例子中,第一个会立即运行,下一个800毫秒之后,下一个800毫秒之后,等等

$('.div_class').each(function(index) {
    // delay inserted before effect (based off index)
    $(this).children().delay(index * 1000).fadeOut('fast', function() {
        $(this).fadeIn('slow');
    });
});
*怒视尼克*

这是另一种方法。这并不使用如上所述的定时延迟,而是使用递归方法,其中一个动画的完成将导致下一个动画的执行

function animate (elms) {
   var target = elms[0]
   if (target) { // guard to ensure still more
       $(target).children().fadeOut('fast', function() {
           $(this).fadeIn('slow')
           // o/` take one down, pass it around,
           //     98 elements of goop in the list o/`
           animate(elms.slice(1))
       }
   }
}
animate($('.div_class').get())

--默认情况下,它使用效果队列。所以,把它放在淡出之前,它就应该做到这一点。快乐编码。嘿,看起来很熟悉…:)完美的清洁,完全按照罐头上说的做-并在10分钟内回答-加油尼克