views:

951

answers:

4

I have several animations that I want to perform on different objects in the dom.

I want them to occur in order.

I do not want to do it like this:

$('#first').show(800, function () 
{ $('#second').show(800, function () {...etc...});

I want to add all my animations(and cpu intensive functions) to some kind of queue object that will make sure they execute sequentially.

+3  A: 

I'm not sure why you don't want to use the method you described. If its purely from an organizational standpoint you don't have to use anonymous functions

function showFirst() {
  $('#first').show(800, showSecond);
}

function showSecond() {
  $('#second').show(800, showThird);
}

function showThird() {
  $('#third').show(800);
}

function startAnimation() {
  showFirst();
}
bendewey
I don't truly need this queue, it would just make organizing code 1000x better.I don't understand why there is not wrapper for any function in a like $(func).joinUniversalQueue();Wow....that is exactly what I want and it would be crazy easy to write such a method/plugin. I'll just do that.
thirsty93
On second thought, $.joinUniversalQueue(func); would be much easier
thirsty93
A: 

Check out the documentation for jQuery Effects. The stuff about queuing should do what you need.

thenduks
I believe those only work for one element though
cobbal
cobbal is correct from what I have read
thirsty93
+2  A: 

http://plugins.jquery.com/project/fxqueues

thirsty93
A: 

I've just used this plugin, http://plugins.jquery.com/project/timers, the other day to do a similar thing. Your basically iterating through all the matched dom elements and then performing an animation each one when the index * your millisecond count.

The code was something like this:

HTML:

<div id="wrapper">
   <div>These</div>
   <div>Show</div>
   <div>In</div>
   <div>Order</div>
</div>

jQuery

$("#wrapper div").foreach( function(i) {
    i = i + 1;
    $(this).oneTime(800 * i, "show", function()  {
        $(this).show();
    });
});
jfar
do these timers stop execution until the animation finishes?
thirsty93
Nope, I used them to chain animations together so that one started while another one finished.
jfar