滚动到 div 底部? [英] Scroll to bottom of div?
本文介绍了滚动到 div 底部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Ajax 请求创建聊天,我试图让消息 div 滚动到底部,但运气不佳.
I am creating a chat using Ajax requests and I'm trying to get messages div to scroll to the bottom without much luck.
我将所有内容都包装在这个 div 中:
I am wrapping everything in this div:
#scroll {
height:400px;
overflow:scroll;
}
有没有办法使用 JS 让它默认滚动到底部?
Is there a way to keep it scrolled to the bottom by default using JS?
有没有办法在ajax请求后让它滚动到底部?
Is there a way to keep it scrolled to the bottom after an ajax request?
推荐答案
这是我在我的网站上使用的:
Here's what I use on my site:
var objDiv = document.getElementById("your_div");
objDiv.scrollTop = objDiv.scrollHeight;
这篇关于滚动到 div 底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文