Expand/contract based on height of content
Hi all, I need to amend a small script that creates tabbed <div>s with content that varies in height. At the moment from what I can gather the boxes are all given the same maximum height based on the tallest content which can vary dramatically.
Any help will be appreciated! Here is the script...
- function createProductTabs() {
- var maxHeight = 0;
- var $tabs = $('<ul id="product-tabs" />');
- var $details = $('#product-details');
-
- $details.find('h2').each(function() {
- $this = $(this);
- $('<li />')
- .append($('<a class="txtWhite noUnderline" />').html($this.text()).attr('href', '#' + $this.parent().attr('id')))
- .appendTo($tabs);
- maxHeight = ($this.parent().height() > maxHeight) ? $this.parent().height() : maxHeight;
- $this.remove();
- });
- $details
- .addClass('bgGradient tabbed')
- .css('height', maxHeight + 'px')
- .children()
- .filter(':first')
- .addClass('current')
- .end()
- .filter(':not(:first)')
- .hide();
- $tabs
- .find('li:first-child a')
- .removeClass('txtWhite')
- .addClass('txtOrange current')
- .end()
- .find('li:last-child')
- .addClass('last-child')
- .end()
- .insertBefore($details)
- .find('a')
- .click(function() {
- $this = $(this);
- $current = $('#product-tabs .current');
- $this
- .removeClass('txtWhite')
- .addClass('current txtOrange');
- $current
- .removeClass('current txtOrange')
- .addClass('txtWhite');
- $($current.attr('href')).fadeOut('fast', function() {
- $($this.attr('href')).fadeIn('fast');
- });
- return false;
- });
- }