我希望图像在被删除之前淡出,但是它会被瞬间删除而不会褪色。这是我的代码:
$('img').fadeOut(3000).delay(1000).remove();
如何在删除之前让用户看到fadeOut效果?
答案 0 :(得分:1)
你可以使用setTimeout(),因为:
$('img').fadeOut(3000, function(){
var $that = $(this); //cache your $(this)
setTimeout(function() {
$that.remove();
//call your other functions
}, 1000)
});
答案 1 :(得分:1)
.delay()
仅影响效果队列。
任何不涉及效果队列的链式方法都不会受到延迟的影响。
尝试
$('img').fadeOut(3000).delay(1000).promise().then(function() {
$('img').remove();
});
或
$('img').fadeOut(3000).delay(1000).promise().then(function() {
$(this).remove();
});
答案 2 :(得分:0)
正如一些人指出延迟在队列中起作用。我建议使用带有超时的函数作为fadeOut([duration],[complete])
示例代码
$('img').fadeOut(3000, function () {
setTimeout(function () {
alert("Removing now");
$('img').remove()
}, 1000)});
答案 3 :(得分:0)
remove
方法不会等待动画完成,因为它不是动画方法。要在动画事件之后进行删除,可以使用queue
方法将函数放入动画队列中:
$('img').fadeOut(3000).delay(1000).queue(function(){
$(this).remove();
});
答案 4 :(得分:-2)
如果最后取出.remove(),它会起作用吗?您可能必须对操作进行排队,以使它们不会同时发生。希望这有帮助!