ubh
03-23-2009, 01:17 AM
Running a loop that checks the position of the scroll bar. If the scroll bar height is the same as its div container it is always positioned at the bottom.
Else the scroll bar is not positioned at the bottom and allowed to scroll freely.
Problem I am having is telling the scroll bar to be positioned back at the bottom if the user scrolls to the bottom again.
Here is my Complete code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
body {text-align:center;}
body div, body p {text-align:left;}
#chatBox {width:600px; margin-left:auto; margin-right:auto;}
#chat {width:500px; height:300px; overflow:scroll; float:left;}
#message{width:500px; float:left;}
#users {width:100px; overflow:scroll; float:right; height:280px;}
</style>
<script type="text/javascript">
function getLoop()
{
var chat = document.getElementById("chat");
var newMessage = document.createTextNode("asdffffffffffffff");
var breaker = document.createElement("br");
if (chat.scrollTop == chat.scrollHeight)
{
chat.scrollTop = chat.scrollHeight;
}
else{}
chat.appendChild(newMessage);
chat.appendChild(breaker);
chat.appendChild(breaker);
reLoop();
}
function reLoop()
{
setTimeout("getLoop()",300);
}
</script>
</head>
<body onload="reLoop()">
<div id="chatBox">
<div id="chat">
asdffffffffffffff<br />
</div>
<div style="width:100px; float:right;">Users</div>
<div id="users">
</div>
<input type="text" id="message" />
<button onclick="sendMessage()">Send</button>
</div>
</body>
</html>
Any help is much appreciated!
Else the scroll bar is not positioned at the bottom and allowed to scroll freely.
Problem I am having is telling the scroll bar to be positioned back at the bottom if the user scrolls to the bottom again.
Here is my Complete code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
body {text-align:center;}
body div, body p {text-align:left;}
#chatBox {width:600px; margin-left:auto; margin-right:auto;}
#chat {width:500px; height:300px; overflow:scroll; float:left;}
#message{width:500px; float:left;}
#users {width:100px; overflow:scroll; float:right; height:280px;}
</style>
<script type="text/javascript">
function getLoop()
{
var chat = document.getElementById("chat");
var newMessage = document.createTextNode("asdffffffffffffff");
var breaker = document.createElement("br");
if (chat.scrollTop == chat.scrollHeight)
{
chat.scrollTop = chat.scrollHeight;
}
else{}
chat.appendChild(newMessage);
chat.appendChild(breaker);
chat.appendChild(breaker);
reLoop();
}
function reLoop()
{
setTimeout("getLoop()",300);
}
</script>
</head>
<body onload="reLoop()">
<div id="chatBox">
<div id="chat">
asdffffffffffffff<br />
</div>
<div style="width:100px; float:right;">Users</div>
<div id="users">
</div>
<input type="text" id="message" />
<button onclick="sendMessage()">Send</button>
</div>
</body>
</html>
Any help is much appreciated!