Here’s what I’d like to achieve: when I enlarge the top div, the bottom div should get smaller (and vice versa) so the parent div size remains fixed.
Note: No frameset or jQuery plugin, please! All I need is a simple JavaScript approach to calculate and change the bottom div height as soon as I resize the top div.
You’re right. The CSS3 resize property isn’t well-supported: IE11 doesn’t understand it at all and in Chrome/Safari/Opera you can only enlarge the element, not resize it smaller.
Thanks a lot, anyway!
Here’s what I’d like to achieve: when I enlarge the top div, the bottom div should get smaller (and vice versa) so the parent div size remains fixed.
This script works well in Firefox, and somewhat in Chrome. The problem seems to be that the browsers have little support for the CSS 3 resize declaration. Perhaps someone else might be able to get the required action across all browsers with this as a starting point.
<script type="text/javascript">
var topObj=document.getElementById("top");
topObj.style.height="200px";
var bottomObj=document.getElementById("bottom");
bottomObj.style.height="200px";
window.frames["myFrame"].onresize = function(){
bottomObj.style.height=400-parseInt(topObj.style.height)+"px"; }
</script>
The other thing to keep in mind is that you can’t read the element height using javascript if the height is only set using CSS. You need to set it for the element as illustrated above or start by setting the height as a style attribute within the element tag as follows.
<div id="top" style="height:200px"></div>
. While the last method works, I know that I am inviting the wrath of the purists by suggesting it in this forum.