Alireza Fallah
Alireza Fallah

Reputation: 4607

Run two functions in the exact same time

I want to slideUp() a div, and when its sliding up, I want to move it down by animate() - in the exact same time .

what I have done so far :

    ln = jQuery("Selector");
    ln.slideUp(1500, function() {
        ln.animate({top: '150px'}, 'slow');
        var Html = jQuery('#last' + id1).html() + jQuery('#last' + id2).html();
        ln.html(Html);
    });

But it slides up first, and then moves down 150px.

I want to call these two functions (slideUp and animate ) in the exact same time, I want to know is it possible or not?

Or does my problem have an easier way to solve ?

P.S : I think this kind of questions has been asked before, like this, but Its not my answer if you read it completely.

Upvotes: 1

Views: 842

Answers (1)

jfriend00
jfriend00

Reputation: 707326

You can do this by using .animate() for both operations and just specifying both changes with properties that you pass to animate. The slideup can be done by specifying a final height of 0 for animate. Using this single animation, jQuery will run both changes together as part of the same animation sequence.

ln.animate({top: '150px', height: 0}, 'slow');

Working demo: http://jsfiddle.net/jfriend00/kKsa4/

Upvotes: 5

Related Questions