How can a vertical scroll bar stay at the bottom w

2019-09-08 05:48发布

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>

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?

2条回答
家丑人穷心不美
2楼-- · 2019-09-08 06:23

Use element.scrollIntoView for the last added element

查看更多
我想做一个坏孩纸
3楼-- · 2019-09-08 06:31

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

var div = $('div');
div.scrollTop( div.get(0).scrollHeight );
查看更多
登录 后发表回答