我有滚动的DIV,我通过$ .get更新此DIV的内容。当新内容(在DIV上)比旧内容更长时,我不知道如何进行自动滚动。
CSS
#chat-conversations{
background-color: red;
width: 150px;
height: 300px;
overflow-x: hidden;
overflow-y: scroll;
}
以下是 Code
答案 0 :(得分:2)
尝试将div的scrolltop设置为div的scrollHeight。
var yourDiv = document.getElementById("chat-conversations");
yourDiv.scrollTop = yourDiv.scrollHeight;
在将内容附加到div之后将其放入$ .get的回调函数中,这会自动将div滚动到新内容。
更新:对不起布鲁夫。我现在离开了一个错字。