我有一个带有动态内容的固定高度 div。当一些内容添加到 div 时,我希望自动滚动到底部。
我在 SO 上找到了 scrollTop = scrollHeight
解决方案,但它在我的情况下不起作用。
$(document).ready(function(){
var text = '<p>some text</p><p>some text</p><p>some text</p><p>some text</p><p>some text</p><p>some text</p><p>some text</p><p>some text</p><p>some text</p><p>some text</p>'
$("#content").html(text);
$("#content").scrollTop($('#content').scrollHeight)
})
#content{
max-height:250px;
overflow-y:auto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="content"></div>
最佳答案
改变
$("#content").scrollTop($('#content').scrollHeight)
到
$("#content").scrollTop($('#content')[0].scrollHeight)
关于jquery - 滚动到具有动态内容的 div 的底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45415437/