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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

positioning 2

Status
Not open for further replies.

everytime

Programmer
Feb 21, 2001
31
0
0
GB
Can anyone tell me how to keep an image in the same position (say the top of the page) when the page is scrolled? I know I could just usse a frame to do this but is there a way to do this without frames?

thanks
 
I know you can with a background image -

{
background-image: url("yourimage.gif");
background-attachment: fixed;
}

As to a fixed 'normal' image, I have seen it done with DHTML, but I am ignorant in that direction. Try


As I have seen a 'watermark' script there that could be adapted to your needs. Dean Owen
 
try this code...

Code:
<html>
<head>
<title>Tek-Tips Workshop</title>
<style type=&quot;text/css&quot;>
.imgclass
{
	position: absolute;
}
</style>
<script language=&quot;JavaScript&quot;>
function keepImage()
{

document.getElementById(&quot;theimgID&quot;).style.pixelTop = document.body.scrollTop;
}
</script>
</head>

<body onScroll=&quot;keepImage();&quot;>
<img class=&quot;imgclass&quot; src=&quot;images/A.gif&quot; id=&quot;theimgID&quot;>

</body>
</html>
[/color]

Here, the most important parts are the stylesheet I gave the image, the javascript:- document.getElementById(&quot;theimgID&quot;).style.pixelTop = document.body.scrollTop; and the HTML <body onScroll=&quot;keepImage();&quot;>
This will keep the image at the top of the window no matter where the user scrolls to.

For testing reasons you will have to fill out the BODY tag so the browser has actually got a reason to present you with scrollbars!

Klae

You're only as good as your last answer!
 
Thanks QuietDean and Klae I will try these out :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top