1

I would like this function to delay each animation inside the each function. That is one after the other. At the moment they all come through together.

$('.bounceholder ul:eq(' + bounceholder + ') li').each(function(){
            $(this).delay(1000).animate({left: bounceoffset, top:-8, opacity:0.6, leaveTransforms:true}, {duration:600, queue:true});
            bounceoffset += 160;
        });

2 Answers 2

3

the block/function you pass to each can accept the counter/index as first argument:

$('.bounceholder ul:eq(' + bounceholder + ') li').each(function(i){
  delay = (i + 1) * 1000
  $(this).delay(delay).animate({left: bounceoffset, top:-8, opacity:0.6, leaveTransforms:true}, {duration:600, queue:true});
  bounceoffset += 160;
});
Sign up to request clarification or add additional context in comments.

Comments

0
function DoAnimation(items, delay, bounceOffSet) {
    $(items[0]).animate({left: bounceoffset, top:-8, opacity:0.6, leaveTransforms:true}, {duration:600, queue:true})
        .delay(delay)
        .promise()
        .done(function() {
            items.splice(0, 1);
            if (items.length > 0)
            {
                DoAnimation(items, delay, bounceOffSet + 160);    
            }            
    });       
}

var items = $('.bounceholder ul:eq(' + bounceholder + ') li');

DoAnimation(items, 1000, 0);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.