jQuery each()有一个延迟 [英] jQuery each() with a delay

查看:262
本文介绍了jQuery each()有一个延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我想要一个元素淡入并等待半秒钟,然后淡出下一个... ...

So, I would like an element to fade in and wait half a second, then fade the next in etc...

我的代码:

$('.comment').each(function() {                 
                    $(this).css({'opacity':0.0}).animate({
                        'opacity':1.0
                    }, 450).delay(500);
                });

我显然做了一件非常愚蠢的事......(我希望)......我的问题是:这甚至可能吗?如果没有 - 有人能指出我正确的方向吗?

I'm obviously doing something really silly.... (I hope)... My question is: Is this even possible? if not - can anyone point me in the right direction?

感谢你!

推荐答案

或者,像这样:

$.each($('.comment'), function(i, el){

    $(el).css({'opacity':0});

    setTimeout(function(){
       $(el).animate({
        'opacity':1.0
       }, 450);
    },500 + ( i * 500 ));

});

demo => http://jsfiddle.net/steweb/9uS56/

这篇关于jQuery each()有一个延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆