Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

have <div> stay at a certain position 1

Status
Not open for further replies.

mackey333

Technical User
May 10, 2001
563
US
how do i make a division stay at a relative position (i.e. when the page is scrolled it stays still and the page scrolls under it) i used to be able to do this but i am out of practice with javascript. thx for any help -Greg :-Q

flaga.gif
 
Here is your solution that works in the latest Opera, IE, Netscape and Mozilla.

<html>
<head>
<title>scroller</title>

<script>

function update()
{
var topOffset = (typeof pageYOffset != &quot;undefined&quot;) ? pageYOffset : document.body.scrollTop;

document.getElementById(&quot;myDiv&quot;).style.top = topOffset;

setTimeout(&quot;update()&quot;, 50) // calls itself every 50 milliseconds
}

</script>
</head>

<body onload=&quot;update()&quot;>

<div id=&quot;myDiv&quot; style=&quot;position:absolute; left:0px; top:0px;&quot;>upperLeft content here</div>

<p>content....</p>
<p>content....</p>
<p>content....</p>
<p>content....</p>
<p>content....</p>
<p>content....</p>
<p>content....</p>
<p>content....</p>

</body>
</html> Gary Haran
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top