Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make jQuery effects run in sequence, not simultaneously?

How do I have two effects in jQuery run in sequence, not simultaneously? Take this piece of code for example:

$("#show-projects").click(function() {
    $(".page:visible").fadeOut("normal");
    $("#projects").fadeIn("normal");
});

The fadeOut and the fadeIn run simultaneously, how do I make them run one after the other?

like image 715
Justin Poliey Avatar asked Sep 16 '08 18:09

Justin Poliey


1 Answers

You can supply a callback to the effects functions that run after the effect has completed.

$("#show-projects").click(function() {
    $(".page:visible").fadeOut("normal", function() {
        $("#projects").fadeIn("normal");
    });
});
like image 86
Jim Avatar answered Sep 29 '22 20:09

Jim