I''m trying to create a sliding menu which is giving me a bit of trouble.
Not a CSS and JQuery guru by any stretch, looking for some pointers, especially with the JQ/JS as toggle looks a lot better but couldn't get it to adapt a class (why I have some CSS classes with "-on") to bring out the menu.
I have browsed some online guides but they weren't doing exactly what I wanted and I didn't fully understand them when it was copy-pasta.
Trying to build my own from scratch but come unstuck, at the moment the grey colour appears on the clicks, but the nav doesn't come with it.
Main objective is to create a basic sliding menu that 'pushes' the content to the right.
Mark Up
<head>
<meta name="viewport" content="width=device-width" />
<link href="~/Content/slide.css" rel="stylesheet" type="text/css"/>
<script src="~/Scripts/jquery-1.5.1.min.js"></script>
<script>
$(function () {
$(".burger_on").click(function () {
$(".page-wrap").removeClass("main-nav");
$(".push-wrap").removeClass("push-wrap");
$(".page-wrap").addClass("main-nav-on");
$(".push-wrap").addClass("push-wrap-on");
return false;
});
});
$(function () {
$(".burger_off").click(function () {
$(".page-wrap").removeClass("main-nav-on");
$(".push-wrap").removeClass("push-wrap-on");
$(".page-wrap").addClass("main-nav");
$(".push-wrap").addClass("push-wrap");
return false;
});
});
</script>
<title></title>
</head>
<body>
<div class="page-wrap">
<div class="main-nav">
<ul>
<li class="nav-item">About</li>
<li class="nav-item">Contact</li>
<li class="nav-item">Home</li>
</ul>
</div>
<div class="push-wrap">
<button class="burger_on">☰</button>
<button class="burger_off">☰</button>
<div class="content">
@RenderBody()
</div>
</div>
</div>
</body>
CSS
body {
font-family: Arial;
background-repeat: repeat-x;
background-position: center top;
background-color: green;
font-size: 0.8em;
}
.page-wrap {
height:100%;
width:100%;
}
.main-nav { /* change width to 20% when menu active*/
width:0%;
transition: 0.3s ease;
background-color: darkgrey;
height:100%;
}
.main-nav-on {
float: left;
width:20%;
transition: 0.3s ease;
background-color: darkgrey;
height: 100%;
}
.push-wrap { /* change width to 80% when menu active*/
width:100%;
height: 100%;
}
.push-wrap-on {
width:80%;
height: 100%;
}