0

I've already found a solution using {queue: true}, but the problem is that this doesn't seem to work in my case.

I've created a fiddle to help you understand my problem: http://jsfiddle.net/c6SS9/1/.

jQuery Code:

$(function() { for(var i=0; i < $('.block').size(); i++) { $('.block').eq(i).delay(i*200).animate({'left': '300px'}, 700); $('.block').eq(i).delay(i*200).animate({'opacity': '1'}, {queue: false, duration: 1000}); } });​ 

What i want is that the animation used for the opacity starts when the block start to move and this has to happen for each block.

2
  • can you not just increase the duration of the opacity animation? Commented Dec 11, 2012 at 1:35
  • But this is not really what I want. What I want is that the opacity animation start when each block starts to move. Commented Dec 11, 2012 at 1:38

1 Answer 1

3

I guess you understand the problem is that the opacity animation bypasses delay as it is not on the queue.

In this case, use the generic .queue() function to add the animations AFTER the delay, so that they are executed after the delay even if they are not on the queue

Updated fiddle

Sign up to request clarification or add additional context in comments.

5 Comments

Can you please tell which is in your opinion the best way to execute a function after the animation of the last block is completed?
If you ask me, I would use complete for the opacity animation
Yes but with {queue: false} in the opacity animation I can't use a callback function. I've tryed and it's not working.
You can still use complete in the options object you pass to .animate(): jsfiddle.net/c6SS9/9. The problem is you want to execute that for only the last block. You can add a class or id to the last block, or use .index() to check if it is the last block, if it is then execute the rest of the function.
Oh, I see. I thought complete and callback function were the same thing, but they're not. Thank you again!!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.