其他功能完成后运行功能

时间:2014-04-26 17:48:21

标签: javascript jquery

我正在寻找一种在其他功能准备就绪时运行功能的方法。

这是功能:

$(".box").first().show(150, function showNext () {

    $(this).next(".box").show(150, showNext);

});

所以我想找到一种方法来运行另一个函数,例如:

alert("Done");

我试过这个但是没有工作。

$(".box").first().show(150, function showNext () {

    $(this).next(".box").show(150, showNext);

}, function () {

alert("Done");

});

我想要的是,用文字:

if(all .box is visble or if showNext is idle/completed){

alert("Done");

}

我感谢任何帮助!感谢。

1 个答案:

答案 0 :(得分:1)

怎么样:

$(".box").first().show(150, function showNext () {
    var next = $(this).next(".box");

    if (next.length > 0) { // If a next sibling with class "box" was found
        next.show(150, showNext);
    } else { // No sibling found, end reached
        alert("Done");
    }
});
相关问题