...

View Full Version : Dynamic div sizing not working in IE



galavantes
08-25-2008, 05:30 AM
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?

galavantes
08-26-2008, 02:03 AM
Bumping, still having this problem. Would really like to get it solved :(

rangana
08-26-2008, 03:28 AM
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 (.):


var cart_height = $("#cart").height() - 210;
$("#cart").height(cart_height);


If cart is an ID, then you should change highlighted to pound sign (#):


.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.

galavantes
08-28-2008, 12:19 AM
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 :)

rangana
08-28-2008, 12:53 AM
So the snippet you provided is lacking. Could you please provide a complete snippet. The problem seems unreproducible on my end.

galavantes
08-28-2008, 06:24 AM
Certainly, the entire file consists of the following 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.

galavantes
08-28-2008, 06:37 AM
Oof, frustrating

galavantes
08-28-2008, 06:58 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum