Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alert Box Running First?

I have some jQuery/JS below. The first thing to run is the alert box at the end.

$(document).ready(function() {
    $("#id1 img , .msg").stop().animate(
        { width: '300px', height: '300px'}, 
        { duration: 'slow', easing: 'easeInSine' }).pause(3000);

    $(".msg").animate(
        { width: '50px', height: '50px' }, 
        { duration: 498, easing: 'easeOutSine' });
    $("#id1 img").animate(
        { width: '50px', height: '50px' }, 
        { duration: 500, easing: 'easeOutSine' });

    $("#id1 img , .msg").animate(
        { width: '300px',height: '300px'}, 
        { duration: 'slow', easing: 'easeInSine' }).pause(3000);

    alert('eh?');
});

I do have a easing plugin.

If I run this the alert will show, and then the first animate will happen in the background but not be shown. It will just appear at the final size.

Shouldn't the alert run at the end of all the animation?

Can anyone explain why this is happening?

like image 764
corymathews Avatar asked Mar 27 '26 09:03

corymathews


2 Answers

As other commenters have mentioned, the animate method is non-blocking and thus this is the correct behavior. If you want the alert to be called at the end of an animation, take a look at the animate method's callback parameter. The documentation states: "A function to be executed whenever the animation completes, executes once for each element animated against."

http://docs.jquery.com/Effects/animate

like image 198
theraccoonbear Avatar answered Mar 29 '26 23:03

theraccoonbear


This pause plugin says that it "holds everything in the queue" for the specified amount of time. It will not actually pause execution (there is no sleep in javascript).

So, this is exactly the expected thing, that the alert will show up first.

like image 28
Victor Avatar answered Mar 29 '26 23:03

Victor