jQuery each() with a delay

前端 未结 5 2008
执念已碎
执念已碎 2021-02-07 08:33

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

My code:

$(\'.comment\').each(function() {                 
          


        
5条回答
  •  [愿得一人]
    2021-02-07 09:27

    Or, something like this:

    $.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/

提交回复
热议问题