2013-12-18 43 views
0

因此,我有一堆用戶可以做它的東西的列表加載其他頁面的內容到一個div什麼會發生當前div的內容閃爍(淡出然後再次),那麼新的內容出現什麼我想要做的是使淡入動畫等到內容準備好加載,然後在這裏DIV褪色是目前使用淡出負載然後淡入不起作用

$(document).ready(function(){ 
    $("#History").click(function(){ 
     $('#Display').fadeOut("fast").load("History.php").fadeIn("fast"); 
    }); 
    $("#Items").click(function(){ 
     $('#Display').fadeOut("fast").load("SellerItems.php").fadeIn("fast"); 
    }); 
}); 

回答

3

兩件事:1,你需要隱藏的div在加載之前,2,在準備就緒時淡入。

我會在這裏動畫的不透明度,而不是使用fadeIn爲更好地控制:

$("#History").click(function(){ 
    $('#Display').css('opacity', 0).load("History.php", function() { 
     $(this).animate({ opacity: 1 }, 'fast'); 
    }); 
}); 
+0

感謝一羣夥計這完美的作品其他閃爍太多,如果有人要使用此 –

1

load方法jQuery代碼亞姆支持回調。
例如:

$('#Display').load("SellerItems.php", function() { 
    $(this).fadeIn("fast"); 
}); 
3

使用隨既​​和load()方法callback function參數。他們將被調用的時候淡出完成,AJAX程序分別完成,:

$("#History").click(function(){ 
    $('#Display').fadeOut("fast", function(){ 
     $(this).load("History.php", function(){ 
      $(this).fadeIn("fast"); 
     }); 
    }); 
}); 
+0

工作正常,非常感謝 –

+0

很高興能有幫助。 – George

+0

在使用承諾執行fadeOut的同時加載內容會更加有效。 – David

1

jQuery的load函數接受的是,當操作完成,就像運行的回調:

$("#result").load("ajax/test.html", function() { 
    alert("Load was performed."); 
}); 

所以你應該做的是回調添加到您的代碼:

$("#History").click(function() { 
    $('#Display').load("History.php", function() { 
    $(this).fadeIn("fast"); 
    }); 
});