Skip to content

Instantly share code, notes, and snippets.

@philcon93
Last active September 29, 2016 22:43
Show Gist options
  • Save philcon93/445b6a848f02e23b53af0a03a579b043 to your computer and use it in GitHub Desktop.
Save philcon93/445b6a848f02e23b53af0a03a579b043 to your computer and use it in GitHub Desktop.
Dynamic Menu splitter

Dynamic Menu splitter

JS

Implemented - Curtis Wilkinson

$(document).ready(function() {
//3 column dicer
function columnDicer(menuClass, colNum) {
var itemTotal = $('' + menuClass + ' .first-col' + ' ' + '>.menu-li').length;
var spliceValue = (itemTotal/colNum) - 1;
var roundedVal = Math.floor(spliceValue);
$('<ul class="column second-col col-xs-12 col-sm-4"></ul><ul class="column third-col col-xs-12 col-sm-4"></ul>').insertAfter($(menuClass + ' .first-col'));
$(menuClass + ' .column.first-col .lv2-li:gt(' + roundedVal + ')').each(function() {
$(this).appendTo($(menuClass + ' .second-col'));
});
$(menuClass + ' .column.second-col .lv2-li:gt(' + roundedVal + ')').each(function() {
$(this).appendTo($(menuClass + ' .third-col'));
});
}
// Class name of top level menu, Cut after this index (zero based)
columnDicer('.sub-cat', 3);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment