Jump to content

Scrollbar position


otester

Recommended Posts

Currently got chat box done using SQL and PHP, however when text overflows the scroll bar won't stay at the bottom..

 

Currently using this code (within header):

 

<script language="text/javascript">

        var objDiv = document.getElementById("site_chat_box");
	objDiv.scrollTop = objDiv.scrollHeight;

</script>

 

Unfortunately it doesn't work  :confused:

 

Any ideas?

 

 

Thanks,

 

otester

Link to comment
Share on other sites

Setting the scrollTop attribute initially won't do any good. You'll have to adjust the scrollTop attribute every time that chat is appended to the div.

 

So is there anyway to achieve what I want to do?

 

I've been hunting around the net and it currently isn't looking very good for me :(

Link to comment
Share on other sites

Just find the part in your script where new messages are added to the div and right after it place that code to update the scrollTop.

 

Ok I changed the code between the header to:

 

<script language="text/javascript">
	var objDiv = document.getElementById("site_chat_box");
</script>

 

I have a file which deals with the database and relaying the message to the div, I added this after the php tags:

 

<script language="text/javascript">
objDiv.scrollTop = objDiv.scrollHeight;
</script>

 

 

Still doesn't work :/

 

Btw I am using overflow-x and overflow-y properties (CSS3).

Link to comment
Share on other sites

Are the messages appended using JavaScript or are the messages loaded when the pages loads? If the latter then you can do something like this:

 

<script type="text/javascript">
window.onload = init;
function init() {
    var objDiv = document.getElementById("testid");
    objDiv.scrollTop = objDiv.scrollHeight;
}
</script>

Link to comment
Share on other sites

Are the messages appended using JavaScript or are the messages loaded when the pages loads? If the latter then you can do something like this:

 

<script type="text/javascript">
window.onload = init;
function init() {
    var objDiv = document.getElementById("testid");
    objDiv.scrollTop = objDiv.scrollHeight;
}
</script>

 

The messages are loaded by fetching them from an SQL database, no JavaScript involved in the process, so when the page loads.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.