Is it possible to combine these two functions?
I have a menu that I toggle when a button is clicked, and when you click off of it or on a link inside of it, it then hides. I also have it set up so that the esc key will close it, but I was curious if I could somehow combine them into one? Heres that I have so far.. everything i've tried doesn't seem to work so if someone could point me in the right direction that would be awesome - Thanks!
- //Toggle functionality for menu
- $(function(){
- var effect = 'slide';
- var options = { direction: 'left'};
- var duration = 500;
-
- //Slide toggle menu
- $('#m').click(function () {
- $('#mOpt').toggle(effect, options, duration);
- });
-
- //Slides menu left to hide when clicking on any <section>
- $('section, a[href*="#"]:not([href="#"])').click(function(){
- $('#mOpt').hide(effect, options, duration);
- });
- //Slides menu left to hide on key up esc
- $(document).on('keydown',function(e) {
- if (e.keyCode == 27) {
- $('#mOpt').hide(effect, options, duration);
- };
- });
- });