jQuery调用在淡出的同时错误地触发

jQuery call incorrectly firing at the same time as fade

本文关键字:错误 调用 淡出 jQuery      更新时间:2023-09-26

我正在构建一个灯箱,我遇到了一个问题,其中以下的fadeIn函数在fadeOut而不是之后同时发射。

为什么updateImage.call(this)fadeOut同时发射?考虑到它被放置为回调,它不应该在之后触发吗?

完整代码段

function updateImage() {
    activeImage = overlayImagesBox.find('.' + this.className);
    activeImage.fadeIn('slow').addClass('active-image');
}
imageLinks.on('click', function (e) {
    e.preventDefault();
    if (!activeImage) {
        updateImage.call(this);
    } else {
        activeImage.removeClass('active-image').fadeOut('slow', updateImage.call(this));
        activeImage = null;
    }
});

正如@blex在评论中提到的,正确的答案是简单地将函数作为回调传递而不是执行它。谢谢大家的帮助。