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:

https://jsfiddle.net/mahdaen/jsf0oc99/3/


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -