I'm currently working on a menu that should open when the button is clicked once and close when clicked again. I had done this before but I seem to have forgotten how to achieve it. Here is the code snippet that I tried to use:
var main = function(){
$('#menuopen').click(function(){
$('.leftbox').show();
$('.leftbox').animate({left: "0"});
$('.topbox').animate({left: "15%", width: "85%"});
},
function(){
$('.leftbox').animate({left: "-15%"});
$('.leftbox').hide();
$('.topbox').animate({left: "0", width: "100%"});
}
);
}
$(document).ready(main);
body {
background-color: #CCCCCC;
}
h2{
text-align: center;
font-family: 'Lato', sans-serif;
}
.topbox{
position: absolute;
top: 0%;
left: 0%;
width: 100%;
height: 10%;
background-color: #006699;
}
.leftbox{
display: none;
position: absolute;
background-color: #FFFFFF;
top: 0px;
left: -15%;
width: 15%;
height: 100%;
box-shadow: 10px 67px 5px #888888;
}
#commentbox{
position: absolute;
top: 87%;
left: 30%;
width: 50%;
resize: none;
border-radius: 5px;
outline: none;
box-shadow: 10px 10px 10px #888888;
}
#submitbox{
position: absolute;
background-color: #006699;
left: 82%;
top: 87%;
height: 66px;
width: 132px;
border-radius: 5px;
border: 0px;
outline: none;
box-shadow: 10px 10px 10px #888888;
font-family: 'Lato', sans-serif;
font-weight:;
}
#menuopen{
position: absolute;
top: 25%;
left: 15px;
height: 32px;
width: 32px;
}
<!DOCTYPE html>
<html>
<head>
<link href='http://fonts.googleapis.com/css?family=Lato' rel='stylesheet' type='text/css'>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript" src="script.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="topbox">
<h2> Lobby </h2>
<img id="menuopen" src="menu_icon.png"/>
</div>
<div class="leftbox">
</div>
<div class="inputbox">
<textarea placeholder="Enter your comment!" id="commentbox" rows="4" cols="50"></textarea>
<input id="submitbox" type="submit" value="Submit">
</div>
</body>
</html>
Can anyone point out what might be the issue with this code? Is the jQuery implementation correct? :O