1

Possible Duplicate:
Scroll to bottom of div?

I'm building a chatroom, and I would like to set it up so the scroll is always kept to the current message. For example, here is my view:

 <div id="chatWrap">
 <div id="chatLog">
<% @chatLog.each do |c| %>
    <% account = getAccountByAccountId(c.account_id) %>
    <div class="chat">
        <div class="chatUsername">
            <p><%= link_to account.username, account_path(account) %> said:</p>
        </div>
        <div class="chatMessage">
            <p><%=h c.message %></p>
        </div>
    </div>
<% end %>   
 </div>

 <textarea id="message" name="message">Type your message here and hit enter...</textarea>

 </div>

Now my css so far is as follows:

 #chatWrap {
width:800px;
margin-left:auto;
margin-right:auto;
 }

 #chatLog {
background-color:#FFFFFF;
padding:10px;
height:500px;
overflow:auto;
color:#161616;
 }

As you can see I set the overflow to auto and fixed the height of the div.

The problem is that every time I send a new message the scroll does not move to the current message.

I was wondering if there is a JQuery solution to this?

Thank you,

Brian

0

1 Answer 1

1

Have a look at jQuery.scrollTop. That should do your job.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.