Is it possible to run two animations on two different elements simultaneously? I need the opposite of this question 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.
yes there is!
If you run the above as they are, they will appear to run simultaenously.
Here's some test code:
See this brilliant blog post about animating values in objects.. you can then use the values to animate whatever you like, 100% simultaneously!
http://www.josscrowcroft.com/2011/code/jquery-animate-increment-decrement-numeric-text-elements-value/
I've used it like this to slide in/out:
I believe I found the solution in the jQuery documentation:
simply add:
queue: false
.While it's true that consecutive calls to animate will give the appearance they are running at the same time, the underlying truth is they're distinct animations running very close to parallel.
To insure the animations are indeed running at the same time use:
Further animations can be added to the 'my-animation' queue and all can be initiated provided the last animation dequeue's them.
Cheers, Anthony
That would run simultaneously yes. what if you wanted to run two animations on the same element simultaneously ?
This ends up queuing the animations. to get to run them simultaneously you would use only one line.
Is there any other way to run two different animation on the same element simultaneously ?