views:

1165

answers:

3

Is it possible to run two animations on two different elements simultaneously? I kinda need the oposite of this question http://stackoverflow.com/questions/668104/jquery-queueing-animations

I need to do something like this

$('#first').animate({ width: 200 }, 200);
$('#second').animate({ width: 600 }, 200);

but to run those two at the same time. The only thing I could think of would be using setTimeout once for each animation, but I don't think it is the best solution..

+5  A: 

Erm... have you tried it? If you use the exact code that you have there, to my understanding of how animate() works, they should run simultaneously.

chaos
exactly what I was thinking, I'll set up a test...
Russ Cam
Here we go -http://jsbin.com/axata . Add /edit to see the code
Russ Cam
+1  A: 

If you run the above as they are, they will appear to run simultaenously.

Here's some test code:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;&lt;/script&gt;
<script>
$(function () {
    $('#first').animate({ width: 200 }, 200);
    $('#second').animate({ width: 600 }, 200);
});
</script>
<div id="first" style="border:1px solid black; height:50px; width:50px"></div>
<div id="second" style="border:1px solid black; height:50px; width:50px"></div>
Andreas Grech
A: 

That would run simultaneously yes. what if you wanted to run two animations on the same element simultaneously ?

$(function () {
    $('#first').animate({ width: '200px' }, 200);
    $('#first').animate({ marginTop: '50px' }, 200);
});

This ends up queuing the animations. to get to run them simultaneously you would use only one line.

$(function () {
    $('#first').animate({ width: '200px', marginTop:'50px' }, 200);
});

Is there any other way to run two different animation on the same element simultaneously ?

Waseem
Psssh this is an old and already answered topic.
BalusC