I want div containing a chat, similar to facebook. If the text content gets longer, ther is y-scroll, but:
- The focus shall be on the newest chat entry
- 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:
- The focus shall be on the newest chat entry
- 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
2 Answers
Reset to default 5You 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
评论列表(0条)