Jakub Arnold Jakub Arnold - 3 months ago 15
Javascript Question

How to run two jQuery animations simultaneously?

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

yes there is!

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

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