views:

40

answers:

1

There are some ready JavaScript (jQuery) splitters, but they require panels height to be set. The problem is, that my website doesn't support fixed height, it just can't. Other thing is that this container can change it's height dynamicly, so I'd like to this splitter to adjust to the panels height.

Is there a script or a way to avoid that?

My idea was to set container's height the bigger panel's height, like:


var lheight = $("#LeftPanel").height();
var rheight = $("#RightPanel").height();

if(lheight > rheight){
    $("#container").css("height", lheight+"px");
} else {
    $("#container").css("height", rheight+"px");
}

but this doesn't seems to be a nice way for me.

Do you have any suggestions?

A: 

You can pass a new value to .height(), like this:

var h = Math.max($("#LeftPanel").height(), $("#RightPanel").height());
$("#container").height(h);

In this case we're just using Math.max() to get the taller one, and setting the height to that.

Nick Craver
it's the same as my code but written simpler. Is a way to do it better? I mean without this height trick?
Ventus
@Ventus - If the panels were children of `#container` it should size automatically...is there a reason that doesn't work, with no JavaScript at all?
Nick Craver
@Nick, actually panels are children of a `#container` and it change size with them. But the point is that `#container` needs CSS `height` property to be set, otherwise splitter doesn't work. Until I will find a better way I will use this `$("#content").height($("#content").height());` it's most simple, since (as you mentioned) panels are children of `#container`.
Ventus
@Ventus - You can also do `$("#content").height(function(i, h) { return h; });`
Nick Craver
Since you have provided good ideas in your answer and comments, I accept it :)
Ventus