连续添加文本时,垂直滚动条如何停留在底部? [英] How can a vertical scroll bar stay at the bottom when text is added continuously?

查看:139
本文介绍了连续添加文本时,垂直滚动条如何停留在底部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个div,它有一个滚动条,这里是我用过的代码:

I have a div and it has a scroll bar here is the code I've used:

<div style="width: 200px; height: 250px; overflow: scroll; overflow-x: hidden; -ms-overflow-x: hidden;" id="container"></div>

将会有更多的文字加入到div中,但是当div扩展后,我怎么能让垂直滚动条保留在条的底部,以便用户可以看到附加的文本?

There will be more text added to the div but when the div does expand how can I have the vertical scroll bar remain at the bottom of the bar so the user can see the appended text?

推荐答案

您应该设置 scrollTop scrollHeight ,例如: http://jsfiddle.net/fAK2L/1/

You should set the scrollTop to scrollHeight, e.g.: http://jsfiddle.net/fAK2L/1/.

var div = $('div');
div.scrollTop( div.get(0).scrollHeight );

这篇关于连续添加文本时,垂直滚动条如何停留在底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆