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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • raknin
    New Member
    • Oct 2007
    • 82

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

    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:whit e;
    width: 370px;
    height: 150px;
    position:relati ve;
    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
  • theS70RM
    New Member
    • Jul 2007
    • 107

    #2
    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

    Comment

    • raknin
      New Member
      • Oct 2007
      • 82

      #3
      Thanks I find a solution.You can see it below. It keep the scrollbar at the bottom.

      simple and clean:

      Code:
      if (obj.scrollHeight > obj.offsetHeight)
       {
              obj.scrollTop = obj.scrollHeight - obj.offsetHeight;
      }

      Comment

      Working...