jQuery 在淡入淡出的同时调用不正确触发
jQuery call incorrectly firing at the same time as fade
我正在构建一个灯箱,并且 运行 遇到以下 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 在评论中提到的那样,正确的答案只是将函数作为回调传递而不是执行它。谢谢大家的帮助。
我正在构建一个灯箱,并且 运行 遇到以下 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 在评论中提到的那样,正确的答案只是将函数作为回调传递而不是执行它。谢谢大家的帮助。