Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I slideUp with animate as a function so that code waits until both events are done

I understand that in order for an even to happen ‘after’ a slideUp the following callback code can be used:

$('#something').slideUp('fast', function() {
   ... stuff to do after the slide is complete...
});

I want to achieve a slideUp with an animation to perform in the same way.

$('#something').slideUp().animate({opacity: 0,duration: 'fast'});

How do I transpose this code into a function that waits until both the slideup and the animation are complete before performing further code?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Something like this??

function animateAndExecute(functionToExecute) {
    $('#something').slideUp().animate({opacity: 0,duration: 'fast'});
    setTimeout(functionToExecute, 400) // Time taken to slide up. Use 600 if u use `slow` for animation duration.
}

and use it like

animateAndExecute(function() {
    // Code to execute after sliding and animating
})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading