Skip to content

Instantly share code, notes, and snippets.

@th3hamburgler
Last active December 14, 2015 01:19
Show Gist options
  • Save th3hamburgler/5005694 to your computer and use it in GitHub Desktop.
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