JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 9th, 2012, 08:46 PM
system_ system_ is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 7 system_ User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 22 m 39 sec
Reputation Power: 0
Resize menu divs based on content

---Edit---
Fixed, was due to a CSS error. The LI element had white-space: nowrap, whereas it should have been in the UL.

The script wouldn't get the full width of the LI due to this, it was getting the width of a wrapped version.
---/Edit---

Hi there,

I have a menu system which is comprised of a horizontal top menu, with each item having a singular submenu. Some of these submenus are being split into a number of columns to prevent them being too long. What I am trying to do at the moment is have the submenu divs auto resize their width and height based on the content inside. I've got height working with no issues, it loops the children of the submenu in order to find the highest column, and assigns the parent that height.

For example, should a submenu have 2 columns, one with a height of 123px and another with a height of 234px, the overall height is altered to 234px. I am trying to apply the same logic to handle widths, however I'm having odd results, some submenus have a nice clean width, some end up with extra padding for a seemingly unknown reason.

I've tried using a combination of both .width() and .outerWidth(), as well as using either of them mixed with some other mathematical functions to ensure that the gap between columns is also covered when assigning the width. However, I simply cannot get it working.

This is the jQuery code I am using to resize:
Code:
$(document).ready( function()
{
	if( $(".menubox.last").children().length > 1 )
	{
		$(".menubox.last").width( $(".menubox.last").width() * $(".menubox.last").children().length );
	}

	var height = 0;
	var heighest;

	$(".menubox").children().each( function( index, value )
	{
		if( !$(this).parent().hasClass( "last" ) )
		{
			$(this).parent().width( ( $(this).parent().width() + ( $(this).outerWidth( true ) * 2 ) ) );
		}

		if( $(this).parent().children().length > 1 )
		{
			$this = $(this);
			if ( $this.outerHeight() > height )
			{
				heighest = this;
				height = $this.outerHeight( true );
			}
			$(this).parent().height( height );
		}
		else
			$(this).parent().height( $(this).outerHeight( true ) );
	});
});


A live example can be found at: patioshoppers.com/tmp/jp3.php

To illustrate my point further, if you visit the above URL and hover above Heating, there is a large run off of white, whereas, Furniture is a lot neater. This comparison can also be made with Grills and Lighting, respectively.

Ideally, I would like to be able to loop through the submenu's children and find each of their widths, and then calculate the total width of those plus the gap between columns (which is a set amount defined in the CSS), but I cannot figure out how to do this.

If anyone has any knowledge on the subject matter and feels they could be of help, please reply. Or, if I have failed to convey the issue I am having, please respond and ask for further information

Thanks.

Reply With Quote
Closed Thread

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Resize menu divs based on content

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap