在JQuery中使用fadeOut()和fadeIn()替换whileWith()

pau*_*ons 1 javascript jquery fadein replacewith jquery-animate

我想要做的就是简单地淡出容器内的所有图像,将#next1的图像替换为#active,之后再将所有图像淡化.

这是我的代码:

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

这不起作用.我发现自己看着空的#active

但是这个;

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

使替换很好,但不是我想要做的动画.

我用chrome和ie得到相同的结果.

Gar*_*y.S 5

我在这里的建议是查看jQuery中的promise/done方法.作为一个例子,你可以这样做:

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

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