对于多个添加的元素,不会继续自动滚动溢出元素

时间:2017-11-22 11:49:34

标签: javascript jquery html css

当我通过jquery overflow:auto将新消息附加到列表时,我试图让一个元素自动滚动到.append div的底部

目前已实现使用:

$(".content-wrapper").scrollTop($(".messages").children().height());

并且它适用于前两个添加的元素,但是当我让它运行更长时间时它会停止自动滚动。

The JS Fiddle is here

如何确保在添加前两条消息后继续滚动?

任何帮助表示赞赏! :)

1 个答案:

答案 0 :(得分:2)

您必须获得scrollHeight$(".content")[0].scrollHeight

所以你将代码更改为:

$(".content-wrapper").scrollTop($(".content")[0].scrollHeight);

Here is the fiddle