简体   繁体   中英

How do I wait for the slideToggle to complete before executing code?

I want to wait for the slideToggle effect to complete before executing the if statement and the fadeIn effect.

div_to_move = $(this).parents("div.kind_div");

div_to_move.slideToggle();
if ($(this).html() == "+") {
    $(this).html("-");
    $("div.kind_to", td).append(div_to_move);
} else {
    $(this).html("+")
    $("div.kind_from", td).append(div_to_move);
}
div_to_move.fadeIn();

How can I do?

You may add a callback to slideToggle :

var div_to_move = $(this).parents("div.kind_div");

div_to_move.slideToggle(400, function () {
    if ($(this).html() == "+") {
        $(this).html("-");
        $("div.kind_to", td).append(div_to_move);
    } else {
        $(this).html("+")
        $("div.kind_from", td).append(div_to_move);
    }
    div_to_move.fadeIn();
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM