Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Urgent! Deadline Tomorrow!

    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
    Last edited by WA; 12-22-2002 at 12:39 PM.

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 ....

  • #3
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    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">





  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •