Jump to content

Preventing a <div> to be refreshed when scrollbar is used


jakeoh

Recommended Posts

I added a shoutbox to my site; messages are displayed in a <div> section and refreshed every couple of seconds. Since there can be lots of messages in this section, scrollbars are used.

 

The problem is, when someone wants to scroll through the messages, he is always brought back to the top by the funcrion that refreshes the shoutbox.

 

Here's the code in the .js file:

 

function showData() {
htmlRequest = ajaxFunction();
if (htmlRequest==null){ // If it cannot create a new Xmlhttp object.
	alert ("Browser does not support HTTP Request");
	return;
} 

htmlRequest.onreadystatechange = function(){
	if(htmlRequest.readyState == 4){
		document.getElementById("shoutarea").innerHTML = htmlRequest.responseText;
	}
}
htmlRequest.open("GET", "outputinfo.php", true);
htmlRequest.send(null);
}

showData();
setInterval("showData()",5000);

 

And here's the code in the php file:

 

<?
include("Include/shoutbox_connect.php");
open_connection();

$shout_query = "SELECT * FROM shoutbox ORDER BY `date` DESC LIMIT 10";
$shout_result = mysql_query($shout_query);
$count = 0;

echo '<div style="border:1px #000000 solid; width:200; height:278px; overflow:auto;">';

while($shout_row = mysql_fetch_array($shout_result))
{
	$shouter_name = $shout_row['username'];
	$shout_content = $shout_row['content'];
	$shout_content = stripslashes($shout_content);
	$shout_date = $shout_row['date'];

	// $dday = substr($shout_date, 8, 2);
	$dday = strftime('%d/%m/%y', strtotime($shout_date));
	$dtime = strftime('%H:%M:%S', strtotime($shout_date));
	$dmonth = substr($shout_date, 5, 2);
	$dyear = substr($shout_date, 0, 4);
	$dhour = substr($shoutdate, 11,2);
	$dminute = substr($shoutdate, 14,2);


	if(($count % 2) != 0)
	{
	echo "<p class='shoutboxCssOdd'><b>$shouter_name</b> said, on $dday &agrave $dtime: <br> $shout_content </p>";
	}
	else
	{
	echo "<p class='shoutboxCssEven'><b>$shouter_name</b> said, on $dday &agrave $dtime: <br> $shout_content </p>";
	}
	$count++;
}

?>
</div>

 

Anyone has a hint on how I can prevent this?

Link to comment
Share on other sites

  • 2 weeks later...

I tried a couple of things but I'm way over my head.

 

I guess I should use the onscroll function to monitor the use of the scrollbar... but then what do I do?

 

How can I do the following:

 

onscroll=stop the setInterval of the showdata() function, and then somehow set it again after a certain time or when the scroll is not used anymore.

 

Help!

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.