I'm new with jQuery and I'm trying to do something quite simple, but it looks like it's not that simple.
I have a menu inside a DIV, the DIV has a width of 500px and the menu of 250px. Over the menu I put a button. The idea is that when someone click on the button the menu goes from the left of the DIV to the right.
Well, it's not working.
A Fiddle: http://jsfiddle.net/KUR52/ and the code:
<div class="menuWrap">
<a href="#" class="button"> MENU </a>
<nav class="menu">
<ul>
<li>Lorem ipsum dolor</li>
<li>Aenean commodo</li>
<li>Aenean massa</li>
<li>Lorem ipsum</li>
<li>Aenean</li>
<li>Aenean massa</li>
<li>Lorem ipsum </li>
<li>Aenean </li>
<li>Aenean massa cum </li>
</ul>
</nav>
CSS
.button {
display: block;
background-color: gray;
height: 50px;
width: 50px;
}
.menuWrap {
width: 500px;
background-color: lightblue;
}
.menu {
position: relative;
/* left:250px; */
left:0;
width: 250px;
background-color: orange;
}
.menu ul{
margin: 0;
padding: 0;
list-style:none;
}
jQuery
$(document).ready(function () {
$('.button').click(function () {
$('.menu').toggle(function () {
$(this).animate({left:'250px'}, 300)
}, function () {
$(this).animate({left:'0px'}, 300)
}
);
});
});
I found a couple of possible solutions but i'm not able to make them work, the most promising was this: jQuery - animating 'left' position of absolutely positioned div when sliding panel is revealed But it didn't took me vary far, mostly because I don't understand parseInt
and how to use the value I get from it.
This is my fail attempt http://jsfiddle.net/W5avM/
What i'm doing wrong?