Skip to content

Instantly share code, notes, and snippets.

@nickdavis
Created January 19, 2015 10:30
Show Gist options
  • Save nickdavis/4277f5d5c2e6163b6c57 to your computer and use it in GitHub Desktop.
Save nickdavis/4277f5d5c2e6163b6c57 to your computer and use it in GitHub Desktop.
An idea on reordering floated menu items to respect their originally intended order (open to improvement!)
jQuery(function( $ ){
/* Reorder Menu */
// If page loads in 'non-mobile' mode reorder our floated menu items
if(window.innerWidth > 800) {
menu_reorder();
$("body").addClass("menu-reordered");
}
else {
$("body").addClass("menu-original");
}
$(window).resize(function(){
// If page is resized out of mobile mode reorder our floated menu items
if ($("body").hasClass("menu-original")){
if(window.innerWidth > 800) {
menu_reorder();
$("body").removeClass("menu-original");
$("body").addClass("menu-reordered");
}
}
// If page is resized into mobile mode reorder our floated menu items
if ($("body").hasClass("menu-reordered")){
if(window.innerWidth < 801) {
menu_reorder();
$("body").removeClass("menu-reordered");
$("body").addClass("menu-original");
}
}
});
function menu_reorder(){
var list = $('#menu-primary-menu');
var listItems = list.children('li.menu-right');
list.append(listItems.get().reverse());
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment