Expand/contract based on height of content

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...

  1. function createProductTabs() {
  2. var maxHeight = 0;
  3. var $tabs = $('<ul id="product-tabs" />');
  4. var $details = $('#product-details');
  5. $details.find('h2').each(function() {
  6. $this = $(this);
  7. $('<li />')
  8. .append($('<a class="txtWhite noUnderline" />').html($this.text()).attr('href', '#' + $this.parent().attr('id')))
  9. .appendTo($tabs);
  10. maxHeight = ($this.parent().height() > maxHeight) ? $this.parent().height() : maxHeight;
  11. $this.remove();
  12. });
  13. $details
  14. .addClass('bgGradient tabbed')
  15. .css('height', maxHeight + 'px')
  16. .children()
  17. .filter(':first')
  18. .addClass('current')
  19. .end()
  20. .filter(':not(:first)')
  21. .hide();
  22. $tabs
  23. .find('li:first-child a')
  24. .removeClass('txtWhite')
  25. .addClass('txtOrange current')
  26. .end()
  27. .find('li:last-child')
  28. .addClass('last-child')
  29. .end()
  30. .insertBefore($details)
  31. .find('a')
  32. .click(function() {
  33. $this = $(this);
  34. $current = $('#product-tabs .current');
  35. $this
  36. .removeClass('txtWhite')
  37. .addClass('current txtOrange');
  38. $current
  39. .removeClass('current txtOrange')
  40. .addClass('txtWhite');
  41. $($current.attr('href')).fadeOut('fast', function() {
  42. $($this.attr('href')).fadeIn('fast');
  43. });
  44. return false;
  45. });
  46. }
    • Topic Participants

    • mike