aburn03
09-26-2003, 11:17 PM
I am attempting to center an image in a users screent. I'm attempting to use the screen.width and screen.height to center the image in the middle of the screen. This is not working though. What I'd really like to do is center in the window so if the resize it remains in the center. Is this possible using the screen object? Any tips to the following code?
<html>
<head>
<script language="JavaScript" type="text/javascript">
<!--
function setPosition()
{
ptext.style.top= screen.height/2 - pic.height/2;
ptext.style.left= screen.width/2- pic.width/2;
}
//-->
</script>
<title>Gavin</title>
</head>
<body onload = "setPosition()">
<p id = "ptext" style = "position: absolute; left:0 top:0">
<img id ="pic" src="Gavin.jpg" height =390
width = 340 ></p>
</body>
</html>
<html>
<head>
<script language="JavaScript" type="text/javascript">
<!--
function setPosition()
{
ptext.style.top= screen.height/2 - pic.height/2;
ptext.style.left= screen.width/2- pic.width/2;
}
//-->
</script>
<title>Gavin</title>
</head>
<body onload = "setPosition()">
<p id = "ptext" style = "position: absolute; left:0 top:0">
<img id ="pic" src="Gavin.jpg" height =390
width = 340 ></p>
</body>
</html>