当其他功能完成时运行功能

Run function when other function is completed

本文关键字:功能 运行 完成时 其他      更新时间:2023-09-26

我正在寻找一种方法,以便在另一个函数准备就绪时运行该函数。

这就是功能:

$(".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");
}

我感谢任何帮助!谢谢

怎么样:

$(".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");
    }
});