toggle/update container height when accordion opens
hello,
I want to set a container's height dynamically (and maybe animate) when I open the accordion menu.
this is my html code
- <div id="top"></div>
- <div id="container">
- <div id="left">
- <div class="logo"></div>
- <nav id="menu">
- <ul class="menu">
- <li><a href="#">link</a></li>
- <li><a href="#">link</a>
- <ul class="submenu">
- <li><a href="#">link</a></li>
- <li><a href="#">link</a></li>
- <li><a href="#">link</a></li>
- <li><a href="#">link</a></li>
- <li><a href="#">link</a></li>
- </ul>
- </li>
- <li><a href="#">link</a></li>
- <li><a href="#">link</a></li>
- </ul>
- </nav>
- <div class="bottom"></div>
- </div>
- <div id="right"><!-- content goes here --></div>
- </div>
- <div id="footer"></div>
and here is my
shortened css
- html, body {
- padding:0;
- margin: 0;
- height: 100%;
- }
- #top, #footer {
- height: 20px;
- position:relative;
- z-index:2;
- }
- #container {
- width: 1000px;
- margin: 0 auto;
- min-height: 100%;
- margin-top: -40px; /*this clears the 40px top&footer overflow */
- overflow: hidden; /*this is sadly needed because of the design*/
- }
- #left {
- width: 230px;
- min-height: 100%;
- float: left;
- position: relative;
- margin-top: 40px;
- }
- #right {
- margin-left: 230px;
- min-height: 100%; /*actually this is not necessary but looks better :) */
- margin-top: 40px;
- overflow: hidden;
- position: relative;
- }
- .logo {
- width: 100%;
- height: 210px;
- }
- nav ul li {
- list-style: none;
- min-height: 30px;
- }
- .bottom {
- width: 100%;
- height: auto;
- position: absolute;
- bottom: 10px;
- }
and here is my jQuery code which isn't good since I misscalculated the amount of submenus
- jQuery(document).ready(function($) {
- var dHeight = $(document).height();
- var wHeight = $(window).height();
- if(dHeight > wHeight) {
- $('#container').css('height', dHeight+'px');
- }else {
- $('#container').css('height', '100%');
- }
-
- $("ul.menu > li > a").click(function(){
- if(false == $(this).next().is(':visible')){
- $('ul.menu ul.sub-menu').slideUp(300);
- }
- $(this).next().slideToggle(300);
- });
- });
the basic idea was that if there is only a little content than set the container height to 100% to fill the browser window but I didn't know how many submenus will be there and now if the container height is 100% the accordion slides under the .bottom and than a part of it dissapears because of the container's overflow hidden.
So this is why I would like to update the height when the accordion opens but I couldn't figure out how.