Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

display:none; element height issue, ifarme shim - multiple colapsable divs

Posted on 2008-06-17
4
Medium Priority
?
1,359 Views
Last Modified: 2013-11-19
Hi All,

I have a the need for a menu (lets call it 'FON - float over nav') to position itself over the main workspace. I have a number of divs that open and close onclick using display:none; function that works great.

The problem comes with IE6 where by the FON has select feilds shining through, no problem I thought and added an iframe shim.

However, dependent on the page load state of the FON, if open I get a height say 300px, if closed I get 0px. When I open the FON from a closed start state the iframe doesn't catch up, i.e. it doesn't pick up the hieght of the now open FON's containing div.

To compound the matter I have colapsible sub elements within the containing FON div.

Is there any way to catch the height on changing the div's state from display:none; to display:'';

Heres an example of the code.


<html>
<head>
<script type="text/javascript">
    <!--
        function hideshow(element) {
                if (element.style.display=="none") 
                {
                    element.style.display="";
                } 
                else 
                {
                    element.style.display="none";
                }
        }
	-->
</script>
</head>
<body>
<div id="toolsleft" onclick="hideshow(document.getElementById('toolsleftopencont'));" title="expand">OPEN/CLOSE THE NAV</div>  
 
<div id="toolsleftopencont" style="display:none;">
 
    <h2 onclick="hideshow(document.getElementById('navgroup1'));hideshow(document.getElementById('navgroup1closed'));">Nav Item Group header</h2>
 
    <div id="navgroup1">
 
        <ul>
            <li>Nav Item</li>
            <li>Nav Item</li>
            <li>Nav Item</li>
            <li onclick="hideshow(document.getElementById('subcont1'));">Expandable Item</li>
            <li id="subcont1" class="subcont" style="display:none;">         
                <ul>
                    <li>Sub Nave Item</li>
                    <li>Sub Nave Item</li>
                    <li>Sub Nave Item</li>
                </ul> 
            </li>  
            <li>Nav Item</li>
            <li>Nav Item</li>
        </ul> 
        
    </div><!-- #navgroup1 -->
    
    <!-- Repeat navs as necessary -->
            
</div><!-- #toolsleftopencont -->
 
<!--[if lt IE 7]>	
<script type="text/javascript">
	var ltoolsH = document.getElementById('toolsleftopencont').offsetHeight;
	alert(ltoolsH);       
	//transparent iframe shim to block select fields from shining through
	document.write("<iframe id='toolsleftiframe' src='BLOCKED SCRIPTfalse;' style='height:"+ltoolsH+"px;position:absolute;z-index:-1;width:100%;filter:mask();'></iframe>");
</script>    
<![endif]-->
</body>
</html>

Open in new window

0
Comment
Question by:canibefrank
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 29

Accepted Solution

by:
Pravin Asar earned 2000 total points
ID: 21814473
Here is a one option, which resize the iframe based on the size of div

 
<html>
<head>
<script type="text/javascript">
    <!--
// Absolute Position
function GetTagPixels(StartTag, Direction) {
   var PixelAmt = (Direction == 'LEFT') ? StartTag.offsetLeft : StartTag.offsetTop;
   while ((StartTag.tagName != 'BODY') && (StartTag.tagName != 'HTML')) {
      StartTag = StartTag.offsetParent;
      PixelAmt += (Direction == 'LEFT') ? StartTag.offsetLeft : StartTag.offsetTop;
   }
   return PixelAmt;
}
// Relative to container
 
function GetTagPosition (tagObj) {
	this.x = tagObj.offsetLeft;
	this.y = tagObj.offsetTop;
    return (this);
}
// Tag Dimension 
function GetTagDimension (tagObj) {
	this.width = tagObj.offsetWidth;
	this.height = tagObj.offsetHeight;
    return (this);
}
        function hideshow(element) {
                if (element.style.display=="none") 
                {
                    element.style.display="block";
                } 
                else 
                {
                    element.style.display="none";
                }
				adjustiframe();
        }
		function adjustiframe() {
		var dTag = document.getElementById('toolsleftopencont');
		var yMargin = 20;
		var xMargin = 20;
		var xpos = GetTagPixels (dTag, "LEFT");
   		var ypos = GetTagPixels (dTag, "TOP");
   		var dim  = GetTagDimension (dTag);
		var iframe = document.getElementById ('toolsleftiframe');
		iframe.style.height =dim.height + yMargin;
		iframe.style.width =dim.width + xMargin;
		}
        -->
</script>
</head>
<body>
<div id="toolsleft" onclick="hideshow(document.getElementById('toolsleftopencont'));" style="position:absolute; z-index:10;left: 10px; top: 10px;" title="expand">OPEN/CLOSE THE NAV</div>   
<div id="toolsleftopencont" style="display:none; width: 400px;">
 
    <h2 onclick="hideshow(document.getElementById('navgroup1'));hideshow(document.getElementById('navgroup1closed'));">Nav Item Group header</h2>
 
    <div id="navgroup1">
 
        <ul>
            <li>Nav Item</li>
            <li>Nav Item</li>
            <li>Nav Item</li>
            <li onclick="hideshow(document.getElementById('subcont1'));">Expandable Item</li>
            <li id="subcont1" class="subcont" style="display:none;">         
                <ul>
                    <li>Sub Nave Item</li>
                    <li>Sub Nave Item</li>
                    <li>Sub Nave Item</li>
                </ul> 
            </li>  
            <li>Nav Item</li>
            <li>Nav Item</li>
        </ul> 
        
    </div><!-- #navgroup1 -->
    
    <!-- Repeat navs as necessary -->
            
</div><!-- #toolsleftopencont -->
<div style="position:absolute; z-index:-1; top:0px; left: 0px;">
<iframe id="toolsleftiframe" src="" style="width: 300px; height:200px; ">
</iframe>
</div>
 
<!--[if lt IE 7]>       
<script type="text/javascript">
        var ltoolsH = document.getElementById('toolsleftopencont').offsetHeight;
        alert(ltoolsH);       
        //transparent iframe shim to block select fields from shining through
        document.write("<iframe id='toolsleftiframe' src='BLOCKED SCRIPTfalse;' style='height:"+ltoolsH+"px;position:absolute;z-index:-1;width:100%;filter:mask();'></iframe>");
</script>    
<[endif]-->
</body>
</html>

Open in new window

0
 

Author Comment

by:canibefrank
ID: 21820618
Hi pravinasar,

That fits the bill perfectly, your a star thanks a lot.
0
 

Author Closing Comment

by:canibefrank
ID: 31467991
Nice one works a treat, exactly whta was required. Thanks.
0
 
LVL 29

Expert Comment

by:Pravin Asar
ID: 21824787
Glad to be of some help.

Thanks for the Grade.

-PA
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This article discusses how to implement server side field validation and display customized error messages to the client.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question