JSFiddle - React, Tailwind, and code Playground
by zerolfc
HTML
<nav id="menusystem" class="">
<ul>
<li>Home</li>
<li>About</li>
<li>Portfolio
<ul>
<li>Web Design</li>
<li>Web Development</li>
<li>Illustrations</li>
</ul>
</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</nav>
<div class="container">
<section class="main">
<h2>Slide Menus</h2>
<button class="menu-change-style" data-position="left" data-type="slide" data-axis="vertical">Show/Hide Left Slide Menu</button>
<button class="menu-change-style" data-position="right" data-type="slide" data-axis="vertical">Show/Hide Right Slide Menu</button>
<button class="menu-change-style" data-position="top" data-type="slide" data-axis="horizontal">Show/Hide Top Slide Menu</button>
<button class="menu-change-style" data-position="bottom" data-type="slide" data-axis="horizontal">Show/Hide Bottom Slide Menu</button>
<h2>Push Menus</h2>
<button class="menu-change-style" data-position="left" data-type="push" data-axis="vertical">Show/Hide Left Push Menu</button>
<button class="menu-change-style" data-position="right" data-type="push" data-axis="vertical">Show/Hide Right Push Menu</button>
</section>
</div>
CSS
/* General styles for all menus */
#menusystem {
background: #47a3da;
position: fixed;
}
#menusystem h3 {
color: #afdefa;
font-size: 1.9em;
padding: 20px;
margin: 0;
font-weight: 300;
background: #0d77b6;
}
#menusystem a {
display: block;
color: #fff;
font-size: 1.1em;
font-weight: 300;
}
#menusystem a:hover {
background: #258ecd;
}
#menusystem a:active {
background: #afdefa;
color: #47a3da;
}
/* Orientation-dependent styles for the content of the menu */
.menu-style-vertical {
width: 240px;
height: 100%;
top: 0;
z-index: 1000;
}
.menu-style-vertical a {
border-bottom: 1px solid #258ecd;
padding: 1em;
}
.menu-style-horizontal {
width: 100%;
height: 150px;
left: 0;
z-index: 1000;
overflow: hidden;
}
.menu-style-horizontal h3 {
height: 100%;
width: 20%;
float: left;
}
.menu-style-horizontal a {
float: left;
width: 20%;
padding: 0.8em;
border-left: 1px solid #258ecd;
}
/* Vertical menu that slides from the left or right */
.menu-style-left {
left: -240px;
}
.menu-style-right {
right: -240px;
}
.menu-style-left.menu-style-open {
left: 0px;
}
.menu-style-right.menu-style-open {
right: 0px;
}
/* Horizontal menu that slides from the top or bottom */
.menu-style-top {
top: -150px;
}
.menu-style-bottom {
bottom: -150px;
}
.menu-style-top.menu-style-open {
top: 0px;
}
.menu-style-bottom.menu-style-open {
bottom: 0px;
}
/* Push classes applied to the body */
.menu-style-push {
overflow-x: hidden;
position: relative;
left: 0;
}
.menu-style-push-toright {
left: 240px;
}
.menu-style-push-toleft {
left: -240px;
}
/* Transitions */
#menusystem, .menu-style-push {
-webkit-transition: all 0.3s ease;
-moz-transition: all 0.3s ease;
transition: all 0.3s ease;
}
/* Example media queries...
JavaScript
$(function () {
$('.menu-change-style').click(function () {
var $this = $(this);
if ($this.data('type') === 'push') {
$('body').toggleClass('menu-style-push menu-style-push-toright');
$('#menusystem')
.removeClass('menu-style-vertical menu-style-horizontal menu-style-right menu-style-left')
.addClass('menu-style-' + $this.data('axis') + ' menu-style-' + $this.data('position'));
} else {
$('#menusystem')
.removeClass('menu-style-vertical menu-style-horizontal menu-style-right menu-style-left menu-style-top menu-style-bottom')
.addClass('menu-style-' + $this.data('axis') + ' menu-style-' + $this.data('position'));
}
$('#menusystem').toggleClass('menu-style-open');
return false;
});
});