【问题标题】:How do I wait for the slideToggle to complete before executing code?如何在执行代码之前等待 slideToggle 完成?
【发布时间】:2010-01-09 15:50:57
【问题描述】:

我想在执行if 语句和fadeIn 效果之前等待slideToggle 效果完成。

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();

我该怎么办?

【问题讨论】:

    标签: javascript jquery effects


    【解决方案1】:

    您可以向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();
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-30
      • 2019-12-22
      • 1970-01-01
      • 2018-05-20
      • 1970-01-01
      • 2017-11-28
      • 2017-10-20
      • 1970-01-01
      相关资源
      最近更新 更多