Results 1 to 3 of 3

Thread: Help with auto adjustable div

  1. #1
    Join Date
    Feb 2008
    Posts
    74
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Post Help with auto adjustable div

    Hello,

    I need some help! I have a div box that sticks 10px away from the right and bottom edge of the browser window and auto adjusts itself when the browser is resized. It works perfectly, however, when the window is resized to it's smallest size either virtically or horrizontally, I get a js error. Here is the code. Can someone please help!

    Code:
    <HTML>
    <HEAD>
    <TITLE>Example</TITLE>
    <script type="text/javascript" language="javascript">
    <!--
    function chk(){
    //width setting
    my_div=document.getElementById("adjustBox")
    left_space=document.getElementById("adjustBox").offsetLeft
    right_space=10
    my_div.style.width=document.body.clientWidth-left_space-right_space
    
    //height setting
    my_div=document.getElementById("adjustBox")
    top_space=document.getElementById("adjustBox").offsetTop
    bottom_space=10
    my_div.style.height=document.body.clientHeight-top_space-bottom_space
    }
    onresize=chk
    onload=chk
    //-->
    </script>
    <style type="text/css">
    <!--
     body {
    overflow: hidden;
    }
    div#adjustBox {
    /*position:absolute;
    top: 0px;
    left: 0px;*/
    padding:10px;
    width:100%;
    height:100%;
    overflow: auto;
    background-color:#ccc;
    overflow-x:auto;
    border:1px solid #000;
    }
    -->
    </style>
    </HEAD>
    <BODY>
    <div style="border:1px solid #517191; background-color:#6688A4; height:18px; width:100%;">&nbsp;</div>
    <div id="adjustBox">
    
    </div>
    </BODY>
    </HTML>
    Last edited by Snookerman; 04-23-2009 at 05:38 PM. Reason: added “Resolved” prefix

  2. #2
    Join Date
    Jul 2008
    Posts
    128
    Thanks
    0
    Thanked 17 Times in 16 Posts

    Default

    Looks like the values are going negative - use Math.abs or Math.max to filter the result.

  3. The Following User Says Thank You to clueful For This Useful Post:

    bigalo (10-17-2008)

  4. #3
    Join Date
    Feb 2008
    Posts
    74
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Default

    Thanks clueful! I tried that and it worked perfectly. And no, it's not my code.

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
  •