只是一个简单的问题。
我有这个链:
$(this).fadeOut(800); //which works good.
然后尝试删除它:
$(this).fadeOut(800).remove(); //makes it remove instantly, without fadeOut effect.
有什么帮助吗?
只是一个简单的问题。
我有这个链:
$(this).fadeOut(800); //which works good.
然后尝试删除它:
$(this).fadeOut(800).remove(); //makes it remove instantly, without fadeOut effect.
有什么帮助吗?
您想尝试使用完整的回调函数fadeOut
:
$(this).fadeOut(800, function(){
$(this).remove(); //This will execute once the fadeOut is completed.
});
可能缓存$(this)
:
var $this = $(this);
$this.fadeOut(800, function(){
$this.remove(); //This will execute once the fadeOut is completed.
});
句法:
.fadeOut([持续时间] [,完成])
在调用remove()
作为链之后fadeOut()
它会在启动动画后立即被调用并且不会等待动画完成;因此,您想利用完整的回调来确保在动画完成后完成。
只是用另一个选项扩展答案,使用promise()和done()
var $this = $(this);
$this.fadeOut(800).css('background-color', 'blue')
.promise()
.done(function () {
$this.remove();
});
remove
在方法的回调中执行fadeOut
方法
$(this).fadeOut(800,function(){
$(this).remove();
});
改为使用$(this).fadeOut(800, function() { $(this).remove(); });
。通过放置.remove()
回调,它只会在动画完成后触发。
使用淡出回调函数
$(this).fadeOut(800,function(){
$(this).remove();
})