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
https://forums.phpfreaks.com/topic/209024-scrollbar-position/
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
https://forums.phpfreaks.com/topic/209024-scrollbar-position/#findComment-1091764
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
https://forums.phpfreaks.com/topic/209024-scrollbar-position/#findComment-1091778
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
https://forums.phpfreaks.com/topic/209024-scrollbar-position/#findComment-1091791
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
https://forums.phpfreaks.com/topic/209024-scrollbar-position/#findComment-1091821
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.