[英]jQuery fadeOut method is not fading out element
我在使用jQuery fadeOut方法時遇到一個特殊的問題。
當我使用下面的代碼時它會逐漸消失。
$('#id').fadeOut("slow" );
但是當我使用下面的代碼時它不會消失,它只是從屏幕上消失了。
$('#id').fadeOut("slow" ).remove();
誰能說出問題是什么?
有什么方法可以使第二個褪色嗎?
謝謝
問題是fadeOut是一種動畫方法,這意味着它會隨着時間的推移而發生,但是你會立即調用remove。 相反,您可以使用fadeOut的回調簽名:
$('#id').fadeOut('slow', function(){
$(this).remove();
});
使用callBack function
,通常在執行parental
任務后會觸發一次CallBacks
。
$('#id').fadeOut("slow",function(){ $(this).remove() } );
您需要等待fadeOut()完成,然后使用完整的回調將其從dom中刪除。
$('#id').fadeOut("slow", function(){
$(this).remove()
} );
這是因為.remove()
方法與動畫同時運行,使得在執行remove()
時#id
尚未完全淡出。
你需要在淡出回調上放置remove()
$('#id').fadeOut( function() { //the fadeout is finished call the callback function
$(this).remove();
});
我很確定你不需要使用remove()
函數,因為fadeOut
在完成淡入fadeOut
也會刪除元素。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.