2013-04-16 44 views
0

我有一個飼料網站,只要MySQL表上有一個新行就會自動更新。這是我的代碼:從頂部jQuery推送飼料

var cacheData; 
var data = $('#refresh').html(); 
var auto_refresh = setInterval(
function() 
{ 
    $.ajax({ 
     url: 'index.php', 
     type: 'POST', 
     data: data, 
     dataType: 'html', 
     success: function(data) { 
      if (data !== cacheData){ 
       //data has changed (or it's the first call), save new cache data and update div 
       cacheData = data; 

       $('#refresh').fadeOut("fast"); 
       $('#refresh').load('index.php?_=' +Math.random()+' #refresh'); 
       $('#refresh').fadeIn("slow"); 
      }   
     } 
    }) 
}, 1000); 

目前,它只是完全淡出,然後淡入新的職位。有沒有辦法將所有其他結果向下滑動,然後淡入淡出,就像FaceBook一樣? 我試過

$('#refresh').animate({top:$('#refresh').height(data); - $('#refresh').height(cacheDate);},"slow"); 
$('#refresh').load('index.php?_=' +Math.random()+' #refresh'); 
$('#refresh').fadeIn("slow"); 

難道是這樣做的嗎?我試圖將這個部門推下新的崗位,然後淡入,但它沒有奏效。任何人都可以發現我爲什麼/我必須做什麼?

感謝

回答

0

創建一個新的div元素,隱藏它,在前面加上它的父容器,並使用slideDown()需要的效果。此外,只能從服務器發回新帖子(比較時間戳)。