Skip to content

Instantly share code, notes, and snippets.

@dustinleer
Last active September 17, 2021 14:12
Show Gist options
  • Save dustinleer/94198579606f75fb23c649fddc74cf5e to your computer and use it in GitHub Desktop.
Save dustinleer/94198579606f75fb23c649fddc74cf5e to your computer and use it in GitHub Desktop.
Moving Nav Items
var
// NAV
navbutton = $('.menu-toggle'),
navWrap = $('.main-nav-wrapper'),
navmenu = $('.main-nav'),
servicemenu = $('.service-menu'),
// WATCHER
watcher = window.matchMedia("(max-width: 1179px)");
// Call listener function at run time
windowWidth( watcher );
// Attach listener function on state changes
watcher.addListener( windowWidth );
function windowWidth( watcher ) {
if ( watcher.matches ) {
// If media query matches
// console.log('x matches');
servicemenu.addClass('attached-nav').detach('.nav-service').appendTo(navWrap);
topmenu.addClass('attached-nav').detach('.nav-top').appendTo(navWrap);
} else {
// console.log('x does not match');
servicemenu.removeClass('attached-nav').detach().appendTo('.nav-service');
topmenu.removeClass('attached-nav').detach().appendTo('.nav-top');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment