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

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -