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 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Dynamic div sizing not working in IE

    I am trying to use jquery's .height function to dynamically size a <div> so that it sits just above the bottom edge of the user's screen, and taking into account 210px of padding from a banner at the top of the page. I am currently using this code:
    Code:

    <style>
    .cart{
    background:#66FFFF;
    position:fixed;
    width:20%;
    height:100%;
    right:10px;
    top:190px;
    }
    </style>

    <script type="text/javascript">
    var cart_height = $("#cart").height() - 210;
    $("#cart").height(cart_height);
    </script>




    This code works perfectly on firefox, however IE7 completely ignores it and sizes the box at 100%. When I print out the results from $("#cart").height() in IE7 it returns 0? Is this a known bug?

  • #2
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Bumping, still having this problem. Would really like to get it solved

  • #3
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    It's confusing. Your CSS and JQUERY script does'nt match altogether.

    Your CSS is referring to an element whose class name is cart.
    Your JS is referring to an element whose id is cart.

    You should fix that first, if cart is a class, then change highlighted to dot (.):
    Code:
    var cart_height = $("#cart").height() - 210;
    $("#cart").height(cart_height);
    If cart is an ID, then you should change highlighted to pound sign (#):
    Code:
    .cart{
    See if fixing those helps, also note that if no unit was specified (pt,em or &#37 then "px" is concatenated to the value.

    Hope that helps.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #4
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I can see why that is confusing, and perhaps bad naming on my part, but it is actually correct. The css style does define class cart, however I also created a div with class=cart as well as id=cart. If that makes sense

  • #5
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    So the snippet you provided is lacking. Could you please provide a complete snippet. The problem seems unreproducible on my end.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #6
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Certainly, the entire file consists of the following code:
    Code:
    <style>
    	.cart{
    		background:#66FFFF;
    		position:fixed;
    		height:100%;
    		width:20%;
    		right:10px;
    		top:190px;
    		overflow:auto;
    	}
    </style>
    
    <script type="text/javascript">
    
    function update_cart(){
    	$("#cart").html("<h3>Refreshing Cart..</h3>");
    	$("#cart").load("cart_contents.php");
    }
    </script>
    
    <div id='cart' class="cart"></div>
    <script type="text/javascript">
    update_cart();
    var c_height = $("#cart").height() - 210;
    $("#cart").height(c_height);
    
    </script>
    This is an include file that is placed on various pages within the site.

  • #7
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oof, frustrating

  • #8
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok well I fixed it, although still not sure what the problem was. Someone another file that was being included above that one was killing .height() from working correctly. I swapped the references and it works fine now. Although I can't see anything in the other file that could possibly do that.


  •  

    Posting Permissions

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