gpt4 book ai didi

javascript - replaceWith() 而 JQuery 中的元素 fadeOut() 和 fadeIn()

转载 作者:行者123 更新时间:2023-11-30 08:12:57 25 4
gpt4 key购买 nike

我想做的很简单,淡出容器内的所有图像,将#next1 的图像替换为#active,然后再次淡入所有图像。

这是我的代码:

$('.logo').fadeOut('slow', function() {
$('#active>img').replaceWith( $('#next1>img') );
}).fadeIn('slow', function() {});

这是行不通的。我发现自己看着空的#active

但这不过;

$('.logo').fadeOut('slow', function() {}).fadeIn('slow', function() {});
$('#active>img').replaceWith( $('#next1>img') );

使替换很好,但不是我正在尝试做的动画。

我在 chrome 和 ie 上得到了相同的结果。

最佳答案

我的建议是查看 jQuery 中的 promise/done 方法。作为示例,您可以执行以下操作:

$('.logo').fadeOut('slow').promise().done(function(logo) {
$('#active>img').replaceWith($('#next1>img'));
$(logo).fadeIn('slow');
});

jQuery promise - http://api.jquery.com/promise/

关于javascript - replaceWith() 而 JQuery 中的元素 fadeOut() 和 fadeIn(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7870225/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com