menu

by Nanang Mahdaen El Agung

HTML

<!DOCTYPE html>
<body>

	<div class="menu">
		<div id="close">
            <div class="menu-close"></div>
		</div>
		<ul>
			<li><a href="#">about</a></li>
			<li><a href="#">blog</a></li>
			<li><a href="#">menu</a></li>
			<li><a href="#">contact</a></li>
		</ul>
	</div>

	<div id="content">
		<div class="menu-open">
		</div>
	</div>

</body>

CSS

body {
	left: 0;
	margin: 0;
    padding: 0;
	overflow: hidden;
	position: relative;
}

/*****MENU STYLING*****/

.menu {
	position: fixed;
	height: 100%;
	width: 285px;
	background-image: url('http://i.stack.imgur.com/IehB7.png');
	background-color: #000;
	left: -285px;
}

.menu ul {
	list-style: none;
	width: 100%;
	margin: 0;
	padding: 0;
	border-top: 1px solid #fff;
}

.menu li {
	border-bottom: 1px solid #fff;
	line-height: 50px;
	padding-left: 20px;
}

.menu a {
	font-family: 'Open Sans', sans-serif;
	font-size: 24px;
	text-decoration: none;
	text-transform: uppercase;
	font-size: 24px;
	color: #fff;
}

.menu a:hover {
	color: rgba(255, 255, 255, .75);
}

#close {
	height: 47px;
	width: 100%;
}

.menu-close {
    height: 24px;
    width: 24px;
    background-color: red;
	cursor: pointer;
	margin-top: 12px;
	margin-left: 20px;
}

/****CONTENT SYTLING****/

#content {
	background-color: gray;
	height: 1000px;
	width: 1000px;
}

.menu-open {
    height: 24px;
    width: 24px;
    background-color: green;
	cursor: pointer;
	margin-top: 12px;
	margin-left: 20px;
}

JavaScript

var main = function() {
    $('.menu-open, .menu-close').click(function() {
        var left = $('.menu').offset().left;
        
        if (left < 0) {
            $('.menu').animate({ left: 0 }, 200);
            $('body').animate({ left: 285 }, 200);
        } else {
            $('.menu').animate({ left: -285 }, 200);
            $('body').animate({ left: 0 }, 200);
        }
    });
};

$(document).ready(main);