By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,605 Members | 2,137 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,605 IT Pros & Developers. It's quick & easy.

div Scrollbar jump upward evry time the div show a new value

P: 82
Hi,

I wrote a chat like application in which I use a div to show what was written by each side. I am using the following CSS code:

[HTML]
.chatBody
{
border:1px solid black;
background:white;
width: 370px;
height: 150px;
position:relative;
top:10px;
left:10px;
overflow-y: scroll;
}
[/HTML]

every time a new value is enter into the DIV the scrollbar of the div jump upwards. What can I do in order to keep the scrollbar alway on the bottom of the DIV?
Thanks
Ronen
Aug 5 '08 #1
Share this Question
Share on Google+
2 Replies


100+
P: 107
everytime you insert a new line into the div, set the scrollbar position using mydiv.scrollTop = newposition;

probably setting it to the height of the div would work although ive not tested that! Make sure you ad + "px" onto any number you use for newposition



Andy
Aug 5 '08 #2

P: 82
Thanks I find a solution.You can see it below. It keep the scrollbar at the bottom.

simple and clean:

Expand|Select|Wrap|Line Numbers
  1. if (obj.scrollHeight > obj.offsetHeight)
  2.  {
  3.         obj.scrollTop = obj.scrollHeight - obj.offsetHeight;
  4. }
  5.  
Aug 5 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.