如何在将文本附加到div时始终看到底线? [英] how to always see bottom line when append text to a div?

查看:94
本文介绍了如何在将文本附加到div时始终看到底线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
使用jQuery滚动到包含大量文本的div底部

Possible Duplicate:
Use jQuery to scroll to the bottom of a div with lots of text

我使用div附加了用户聊天的上下文,但是,我发现,每当更新聊天上下文时,都说div中有超过100行,但是它始终显示前几行取决于div的高度.如果要查看其他行,则必须拖动垂直滚动条,但是我想显示最新的上下文,该上下文始终是最后一行.如何做到这一点?

I use div to append context that user chat, however, I found that whenever update chat context, say there are over 100 line in div, but it always shows the first several line depends on the height of div. If you want to see other lines, you have to drag vertical scrollbar, but I want to display the latest context, which is always the last line. How to accomplish that?

推荐答案

我只是将其组合在一起: http://jsfiddle.net/purmou/Bk5vV/

I just threw this together: http://jsfiddle.net/purmou/Bk5vV/

我这样做的目的是,当您单击发送"按钮(模拟一个聊天框)时,它将新聊天内容"附加到可滚动div的末尾,并使用jQuery scrollTo插件.

I made it so that when you click the "Send" button (which simulates a chat box), it appends "New Chat Content" to the end of the scrollable div, and also scrolls to the end of the div using the jQuery scrollTo plugin.

这是jQuery:

$(document).ready(function() {
   $("#newchat").click(function() {
      $("#scroll").append("<br>New chat content.");
      $("#scroll").scrollTo('100%');
   }); 
});

更多有关ScrollTo的信息: http://plugins.jquery.com/project/ScrollTo

More on ScrollTo here: http://plugins.jquery.com/project/ScrollTo

这篇关于如何在将文本附加到div时始终看到底线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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