i have a scrollable div on my site but since the content inside is AJAX-driven and is refreshed every second...the div keeps scrolling back up!how do i prevent this? heres the div itself:
$show = '<div class="chatlist" >';
while($row = mysql_fetch_array($sql))
{
$messages = $row['messages'];
$userid = $row['id'];
$name = $row['name'];
$show.='
<span class="nm" >' . $name . ':</span><br/><span class="msg">' . $messages . '<br/></span>
';}
$show.='</div>';
echo $show;
heres the css:
<style type="text/css">
div.chatlist
{
border: thin dotted #000;
width: 600px;
left:600px;
top:600px;
height:600px;
background-color: #000;
color: #FFF;
border-radius: 5px;
overflow: scroll;
}
span.nm{
font-weight: bold;
text-align:left
}
span.msg{
text-align: right;
font-style: italic;
}
</style>
Also only one CSS rule for both the spans is getting followed.any way around this?
You can set a DIV's scrollTop
property using JavaScript:
https://developer.mozilla.org/en/DOM/element.scrollTop
So you would save the value before the content is updated and reinsert it after the update is complete.