2011-09-06 246 views
0

我有一個自動滾動到底部的d​​iv。但是,每當在一個聊天帖子中使用很多笑臉,自動滾動停止正常工作,它從底部滾動2行。DIV自動滾動不起作用

我也嘗試使用這個..

$("#chatbox").animate({ scrollTop: newscrollHeight }, 'normal'); 

但DIV自動加載每3秒,所以每次它加載動畫效果將顯現。

我可以在什麼地方使用以確保其正常工作?

這裏是全功能...

setInterval(function loadLog(){  
     var oldscrollHeight = $("#chatbox").prop("scrollHeight") - 20; 
     $.ajax({ 
      url: "log.php", 
      cache: false, 
      success: function(html){   
       $("#chatbox").html(html); //Insert chat log into the #chatbox div    
       var newscrollHeight = $("#chatbox").prop("scrollHeight") - 20; //Scroll height after the request 
       $("#chatbox").animate({ scrollTop: newscrollHeight }, 'normal'); //Autoscroll to bottom of div 

      }, 
     }); 
    }, 3500); 

回答

0
setInterval(function(){scroller()}, 3500);
function scroller(){ 
$("#chatbox").load("log.php"); 
$("#chatbox").each(function(){ 
var scrollHeight = Math.max(this.scrollHeight, this.clientHeight); 
this.scrollTop = scrollHeight - this.clientHeight; 
}); 
}