javascript - div containing a chat, focus on last entry - Stack Overflow

I want div containing a chat, similar to facebook.If the text content gets longer, ther is y-scroll, b

I want div containing a chat, similar to facebook. If the text content gets longer, ther is y-scroll, but:

  1. The focus shall be on the newest chat entry
  2. A very long word should do a line break

js fiddel code

CSS

.chat{
width: 230px;
    height: 310px;

margin-left: 10px;
background-color: grey;
    border: solid 1px black;

overflow-y:scroll;
}

I want div containing a chat, similar to facebook. If the text content gets longer, ther is y-scroll, but:

  1. The focus shall be on the newest chat entry
  2. A very long word should do a line break

js fiddel code

CSS

.chat{
width: 230px;
    height: 310px;

margin-left: 10px;
background-color: grey;
    border: solid 1px black;

overflow-y:scroll;
}
Share Improve this question asked May 31, 2013 at 15:44 kaputukaputu 1412 gold badges4 silver badges10 bronze badges 1
  • 2 word-wrap: break-word;; for the second you need javascript – bwoebi Commented May 31, 2013 at 15:47
Add a ment  | 

2 Answers 2

Reset to default 5

You have to scroll to the bottom when a new message es in and you have to use JavaScript to do it (there might be a clever CSS way I don't know, though).

If you're using jQuery (and I'd remend you do), you can do it something like this:

// when a new message es in...
var $chat = $(".chat");
$chat.scrollTop($chat.height());

You might want to change the selector from $(".chat") -- that will probably scroll all chats, which you wouldn't want.

You can also do it with vanilla JavaScript:

// when a new message es in...
var chatEl = document.getElementById("#mychatelement");
chatEl.scrollTop = chatEl.scrollHeight;

For a scrolling part refer to jQuery Scroll to bottom of page/iframe

As for line brakes - it should be like this automatically.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744363370a4570579.html

相关推荐

  • javascript - div containing a chat, focus on last entry - Stack Overflow

    I want div containing a chat, similar to facebook.If the text content gets longer, ther is y-scroll, b

    8天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信