Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am working on a simple slide-in menu system. I'd like to be able to close a menu by hitting the ESC key.

Here's my current code: http://jsfiddle.net/3w539Lct/3/

Line 126 of my Javascript, you can see:

$( document ).on( 'keydown', function ( e ) {
            if ( e.keyCode === 27 ) { // ESC
                $(".menu-wrap").prop("checked", false);
            }
        });

However, this doesn't work. Can someone help?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
188 views
Welcome To Ask or Share your Answers For Others

1 Answer

I reused some of your existing functions and variables. This should be correct.

The element $(."menu-wrap") is a div, and doesn't have a checked property. You need to add the logic of hiding the menu on escape button press.

     $( document ).on( 'keydown', function ( e ) {
        if ( e.keyCode === 27 ) { // ESC
             isOpen && classie.remove( bodyEl, 'show-menu' );
        }
    });

Here's a working demo


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...