How to run two jQuery animations simultaneously?

Jakub Arnold picture Jakub Arnold · Aug 9, 2009 · Viewed 152.5k times · Source

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.

Answer

Joshua picture Joshua · Jan 18, 2011

yes there is!

$(function () {
    $("#first").animate({
       width: '200px'
    }, { duration: 200, queue: false });

    $("#second").animate({
       width: '600px'
    }, { duration: 200, queue: false });
});