...

View Full Version : javascript floating menu timing



gong
10-05-2011, 10:04 AM
Hello everyone,

I tried to create javascript float menu and this my 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>
</head>

<body>
<div id="static" style="width:150px; height:150px; position: absolute; border:1px solid yellow; right: 5px;">HELLO</div>

<script type="text/javascript">
setInterval("document.getElementById('static').style.top=document.body.scrollTop+25+'px' ",1000).setTimeout(100);
</script>
<br /><br /><br />

text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />'
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
text-here
text-here
text-here
text-here
text-here<br /><br /><br />
</body>
</html>


but the results it's not good like: http://www.jtricks.com/javascript/navigation/floating.html

what's the lack or mistake of my script?

please help me

thank you

Old Pedant
10-05-2011, 08:56 PM
That .setTimeout(100) on the end of your code is WRONG. Totally bogus.

Your real problem is that you are asking the scroller to reset its position ONLY ONE TIME PER SECOND. Just change the interval to something MUCH smaller.



setInterval("document.getElementById('static').style.top=document.body.scrollTop+25+'px' ",40);
</script>

In addition to getting rid of the setTimeout, of course.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum