...

View Full Version : Urgent! Deadline Tomorrow!



RosalindD
12-22-2002, 10:46 AM
Alright, here's the last problem I have- I promise:

Use the 'screen' object to get the size of the user's screen, then use this information to place an image (using dynamic positioning, such as 'absolute' or 'resolute') in the middle of the page.

Now, what I did was to put down in the image style "position: absolute; left: 50%; top: 50%" That puts the image in the center but I still feel I'm doing something wrong. I didn't use the 'screen' object and for some reason the picture isn't in the exact middle. Its off a little farther to the right. I'm in dire need of assistance! Please! It just has to be a small little script. Nothing big. Beginning level. Nothing fancy.

Admin note: Please read our posting guidelines regarding how to select an appropriate subject for your thread: http://www.codingforums.com/postguide.htm

brothercake
12-22-2002, 01:18 PM
If left is at 50% then the central object will appear offset - it's left edge is in the middle - but what you want is for its middle to be in the middle.

You just need to make one small change to your calculation of the left position ....:thumbsup:

Mr J
12-22-2002, 03:14 PM
Please try the following

If you do not what to use the setTimeout method then include

onload="centerme()" in the opening BODY tag









<script>

function centerme(){
document.getElementById("pic").style.pixelLeft=document.body.scrollWidth/2 - document.getElementById("pic").width/2
}

setTimeout("centerme()",1000)

</script>


<img id="pic" src="pic1.jpg" style="position:absolute">



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum