更新DIV内容后自动向下滚动 [英] Auto scrolldown after update DIV content
本文介绍了更新DIV内容后自动向下滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的DIV带有Scroll-y,并且我通过$ .get更新了该DIV上的内容.当新内容(在DIV上)比旧内容长时,我不知道如何进行自动向下滚动.
I have DIV with scroll-y and I update content on this DIV via $.get. I don't know how I can make auto scrolldown when new content (on DIV) is longer than old content.
CSS
#chat-conversations{
background-color: red;
width: 150px;
height: 300px;
overflow-x: hidden;
overflow-y: scroll;
}
这是 代码
Here is the Code
推荐答案
尝试将div的滚动顶部设置为div的scrollHeight.
Try setting your div's scrolltop to your div's scrollHeight.
var yourDiv = document.getElementById("chat-conversations");
yourDiv.scrollTop = yourDiv.scrollHeight;
在将内容附加到div之后,将其放入$ .get的Callback函数中,这将自动将div滚动到新内容.
Put this inside $.get's Callback function after appending content to div, this will auto scroll div to the new content.
更新:对不起.我现在留下错字了.
Update: Sorry bruv. i left a typo.corrected now
这篇关于更新DIV内容后自动向下滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文