Search code examples
jquerydelayeach

jquery: how can I delay the each() from being triggered


How can I delay each() from being triggered?

This is the code that delays each box from fading out at certain time given.

$(document).ready(function(){

    var delay = 0;
    $('.block-item:lt(16)').each(function(){ 

        //^^ do for every instance less than the 16th (starting at 0)
        $(this).delay(delay).animate({
            opacity:0
        },500);
        delay += 500;

    });


});

But I want to delay about five second before the each() is triggered. Is it feasible?

Here is the link.


Solution

  • If it is just a matter of delaying the initial animation, why not just start with a 5000 delay?

    http://jsfiddle.net/QAWTy/1/

    $(document).ready(function(){
    
        var delay = 5000;
        $('.block-item:lt(16)').each(function(){ 
    
            //^^ do for every instance less than the 16th (starting at 0)
            $(this).delay(delay).animate({
                opacity:0
            },500);
            delay += 500;
    
        });
    
    
    });