Advanced Search

Results 1 to 2 of 2

Thread: Problem changing margin with onLoad event!!!

  1. #1
    Join Date
    Dec 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problem changing margin with onLoad event!!!

    Hi, I've been searching for 2 days now but can't figger it out. I'm trying to change the top margin of a layer depending on a users screen resolution.
    Here's what I have so far:

    A container layer and a content layer:

    <style type="text/css">
    <!--
    #container {
    position:absolute;
    width:450px;
    z-index:1;
    overflow: hidden;
    height: 600px;
    }
    #content {
    position:absolute;
    width:450px;
    z-index:2;
    background-color: #B8B8B8;
    height: 600px;
    top: 0px;
    left: 0px;
    }
    -->
    </style>

    I made a function to adjust the top margin according to the resolution:

    <script type="text/javascript">
    function adjustMargins()
    {
    if (screen.width==800||screen.height==600)
    {
    document.getElementById('container').style.marginTop=="10px";
    }
    else if (screen.width==1024||screen.height==768)
    {
    document.getElementById('container').style.marginTop=="30px";
    }
    else
    {
    document.getElementById('container').style.marginTop=="50px";
    }
    }
    </script>

    Then I have my 2 layers in the body and the onload event for the body:

    <body onload="adjustMargins()">
    <div id="container">
    <div id="content">blablablabla</div>
    </div>
    </body>

    BUT IT DOESN'T WORK. It does work if I use document.write("Something"), so the resolution get's detected, but something must be wrong with the document.getElementById('container').style.marginTop=="50px"; part.

    Can someone help me out here, plz?

    Greetz,
    D.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,704
    Thanks
    43
    Thanked 3,133 Times in 3,097 Posts
    Blog Entries
    12

    Default

    You want:

    document.getElementById('container').style.marginTop="10px";

    not:

    document.getElementById('container').style.marginTop=="10px";

    The == is only for comparison, to set something equal, use just =
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

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