只是一个简单的问题.
我有这个链:
$(this).fadeOut(800); //which works good.
Run Code Online (Sandbox Code Playgroud)
然后尝试删除它:
$(this).fadeOut(800).remove(); //makes it remove instantly, without fadeOut effect.
Run Code Online (Sandbox Code Playgroud)
有帮助吗?
您想尝试使用完整的回调函数fadeOut:
$(this).fadeOut(800, function(){
$(this).remove(); //This will execute once the fadeOut is completed.
});
Run Code Online (Sandbox Code Playgroud)
可能缓存$(this):
var $this = $(this);
$this.fadeOut(800, function(){
$this.remove(); //This will execute once the fadeOut is completed.
});
Run Code Online (Sandbox Code Playgroud)
句法:
.fadeOut([duration] [,complete])
虽然在启动动画后立即调用remove()as作为链,fadeOut()但不会等待动画完成; 因此,您希望利用完整的回调来确保在动画完成后完成此操作.
只是使用promise()和另一个选项来扩展答案done()
var $this = $(this);
$this.fadeOut(800).css('background-color', 'blue')
.promise()
.done(function () {
$this.remove();
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
105 次 |
| 最近记录: |