我有一个固定高度的动态内容div。我想自动滚动到底部时,一些内容被添加到div。
我在上面找到了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/