如何在jquery中自动滚动到底部并自动刷新

我正在使用此jquery ajax从数据库接收消息。 但是当有人试图发送一个消息然后它来到这里但无法自动滚动到底部。 任何的想法?

setTimeout(startRefresh,1000); var myKeyVals = { some value }; var saveData = $.ajax({ type: 'POST', url: "https://example.php", data: myKeyVals, success: function(resultData) { $("#chatwindow").html(resultData); //###################################### } }); saveData.error(function() { alert("Something went wrong"); }); 

您可以在ajax success使用animatescrollTop尝试一些事情:

 $("html, body").animate({ scrollTop: $(document).height() - $(window).height() }, 'slow'); 
 div {height: 900px; border:2px solid #333; padding:10px;} 
  
DATA FOR SAMPLE 1
SAMPLE DATA
SAMPLE DATA

看看这个: https : //www.electrictoolbox.com/jquery-scroll-bottom/

以下Javascript将使用jQuery将页面滚动到底部:

 $('html, body').animate({scrollTop:$(document).height()}, 'slow'); 

显然,您可以将动画速度(上例中的“慢”)更改为其他内容,例如“快速”或数字持续时间(以毫秒为单位),数字越大,动画越慢。

要将滚动函数绑定到对页面中现有元素执行的单击,请执行以下操作,其中#someID是元素的ID:

 $(document).ready(function() { $('#someID').click(function(){ $('html, body').animate({scrollTop:$(document).height()}, 'slow'); return false; }); }); 

你可以尝试这个技巧。 看看这是否有助于你:

 $("html, body").animate({ scrollTop: $(document).height() }, 20000); setTimeout(function() { location.reload(); },20000);