Skip to content

Instantly share code, notes, and snippets.

@fredkelly
Created March 14, 2011 21:59
Show Gist options
  • Save fredkelly/869965 to your computer and use it in GitHub Desktop.
Save fredkelly/869965 to your computer and use it in GitHub Desktop.
/*************************************************
** jQuery Nice Menus version 1.0.0
** copyright Fred Kelly, licensed GPL & MIT
** http://fredkelly.net/
**************************************************/
(function($){
$.fn.menus = function() {
return this.each(function() {
obj = $(this);
$items = obj.children('li');
var combined = 0;
var current = 0;
// grab combined with of all list items
$items.each(function() {
combined += $(this).outerWidth();
});
$items.each(function(i) {
var output = Math.floor(($(this).outerWidth()/combined)*100*(obj.width()/100));
current += output;
// add pixels left after rounding down
if ((i+1)==$items.size()) {
output += obj.width()-current;
}
// remove borders & padding from output
output -= $('a:first', this).outerWidth()-$('a:first', this).width();
$('a:first', this).css('width', output + 'px');
});
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment