Skip to content

Instantly share code, notes, and snippets.

@th3hamburgler
Last active December 14, 2015 01:19
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save th3hamburgler/5005694 to your computer and use it in GitHub Desktop.
jQuery function to allow for nav menu's with flexible withs and dropdowns that can 'outgrow' their parent. Usage flexible_fixed_nav('#nav > ul > li');
function flexible_fixed_nav(selector) {
var $items = $(selector);
if (!$items.length) return;
$items
.each(
function (index, parent) {
var parentWidth = $(parent).width();
var childWidth = 0;
var $childList = $(parent).find('> ul');
$childList.show();
childWidth = $childList.width();
$childList.css('display', '');
$(parent).find('> ul').width(childWidth);
$(parent).width(parentWidth);
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment