Side Menu | development

| detail

The project originated when working on a project that required a responsive vertical menu that has a show/hide function. The project began with a simple side menu and evolved to be responsive with custom Javascript added to allow for the closing of the menu on tab selection and the introduction of show/hide buttons.

An example can be found here

| html

    <body class="accordionMenuPush">
        <nav class="accordionMenuOn accordionMenuVertical accordionMenuRight" id="accordionMenu">
            <div id="showRight2" class="navs menuBar2">
                <img src="images/close.png" width="30px" height="30px" />
            </div>
            <div id="navigation" class="">
                <a href="#" class="navs">Home</a>
                <a href="#" class="navs">Menu 1</a>
                <a href="#" class="navs">Menu 2</a>
                <a href="#" class="navs">Menu 3</a>
                <a href="#" class="navs">Menu 4</a>
            </div>
        </nav>
        <div id="showRight" class="navs menuBar">
            <span class="bar"></span>
            <span class="bar"></span>
            <span class="bar"></span>
        </div>
    </body>
                        

| css

                            body, html {
    font-size: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    font-family: 'Open Sans', sans-serif;
    font-weight: 100;
}

body {
    background-image: url(images/mainBackground.jpg);
    background-repeat: no-repeat;
    background-position: center center;
    background-attachment: fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
    -webkit-animation: fadeIn 1s;
    animation: fadeIn 1s;
}

::-webkit-scrollbar { 
    display: none; 
}

/* General Styles */

a {
    color: #fff;
    text-decoration: none;
}

h1 {
    margin: 0;
    font-size: 2.8em;
    font-family: 'Open Sans', sans-serif;
    font-weight: 200;
    color: #fff;
    text-align: center;
    padding: 0px 20px;
}

p {
    font-size: 1em;
    line-height: 1.6em;
    font-family: 'Open Sans', sans-serif;
    color: #fff;
    text-align: center;
    padding: 0px 20px;
}

/* General menu styles */

#accordionMenu {
    z-index: 1000;
}

#navigation {
    margin-top: 70px;
}

.accordionMenuOn {
    background: #d1d8e4;
    position: fixed;
}

.accordionMenuOn h3 {
    color: #fff;
    font-size: 1.5em;
    padding: 30px;
    margin: 0;
    font-weight: 300;
    background: #333;
}

.accordionMenuOn a {
    display: block;
    color: #6b717b;
    font-size: 1.05em;

}

.accordionMenuOn a:hover {
    background: #2b2e33;
    color: #fff;
}

.accordionMenuOn a:active {
    background: #555;
    color: #fff;
}

/* Orientation-dependent styles for the content of the menu */

.accordionMenuVertical {
    width: 240px;
    height: 100%;
    top: 0;
    z-index: 1000;
}

.accordionMenuVertical a {
    padding: 15px 35px;
}

/* Vertical menu that slides from the right */

.accordionMenuRight {
    right: -240px;
}
.accordionMenuRight.accordionMenuOpen {
    right: 0px;
}

/* Push classes applied to the body */

.accordionMenuPush {
    overflow-y: visible;
    overflow-x: hidden;
    position: relative;
    left: 0;
}

/* Transitions */

.accordionMenuOn,
.accordionMenuPush {
    -webkit-transition: all 0.3s ease;
    -moz-transition: all 0.3s ease;
    transition: all 0.3s ease;
}

/* Button styles */

.menuBar {
    display: block;
    position: fixed;
    float: right;
    padding: 20px;
    right: 0px;
    cursor: pointer;
    z-index: 900;
}

.bar {
    display: block;
    width: 30px;
    height: 2px;
    margin-bottom: 8px;
    background-color: #fff;
}

.menuBar2 {
    display: block;
    position: relative;
    float: right;
    padding: 20px;
    cursor: pointer;
}

                        

| JavaScript

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>

<script src="scripts/modernizr.custom.js"></script>

<script src="scripts/classie.js"></script>

<script>
var menuRight = document.getElementById('accordionMenu'),

anchors = document.getElementsByClassName('navs'),

body = document.body;

for (var i = 0; i < anchors.length; i++) {
    var anchor = anchors[i];
    anchor.onclick = function() {
        classie.toggle(this, 'active');
        classie.toggle(menuRight, 'accordionMenuOpen');
    }
}

</script>