javascript - Toggle menu on click of two elements -
var main = function() { $('#menu-open').click(function() { $('.menu').animate({ left: '0px' }, 200); $('body').animate({ left: '285px' }, 200); }); $('#menu-close').click(function() { $('.menu').animate({ left: '-285px' }, 200); $('body').animate({ left: '0px' }, 200); }); }; $(document).ready(main);
i want able close menu click of #menu-close
or #menu-open
when menu open. how can this?
you can bind single function both open/close button. inside function, check menu status. example:
$('.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); } });
edit
this updated fiddle:
Comments
Post a Comment