When I first click on the #menuIcon
div I want it to animate the #menu
div left: 0em
and then when I click on it a second time animate #menu
to left: -12em
.
The first part works but when I click again nothing happens. #menuIcon
is a child of #menu
, does this affect anything?
Here's my JS (adapted from this question, the micro query plugin answer):
$(document).ready(function(){
jQuery.fn.clickToggle = function(a,b) {
function cb(){
[b,a][this._tog^=1].call(this);
}
return this.on("click", cb);
};
$("#menuIcon").clickToggle(function() {
$("#menu").animate({left: "0em"}, 500);
}, function() {
$("#menu").animate({left: "-12em"}, 500);
});
});
Thanks in advance.
As suggested by John S here's the relevant(I think) html:
<div id="menu">
<div id="menuIcon">
<div id="menuIcon1"></div>
<div id="menuIcon2"></div>
<div id="menuIcon3"></div>
</div>
</div>
And css:
#menu {
width: 16em;
height: calc(100% - 5em);
background-color: blue;
position: fixed;
bottom: 0;
left: -12em;
}
#menuIcon {
height: 4em;
width: 4em;
position: relative;
top: 0;
left: 12em;
background-color: green;
}