Search code examples
jquerykeypress

jQuery Esc Keypress bind


I'd like to add a bind in which the Esc key will slide my panel back up. Here is my jQuery code.

$(document).ready(function () {

    $(".port-link-container").click(function () {
        $("div.slider-panel").slideUp("slow");
    });

    $("#wr").click(function () {
        $('html, body').animate({ scrollTop: 450 }, 'slow');
        $("div#wr-large").slideDown("slow");
    });

    $("#sema").click(function () {
        $("div#sema-large").slideDown("slow");
    });

    $(".slider-close").click(function () {
        $('html, body').animate({ scrollTop: 0 }, 'slow');
        $("div.slider-panel").slideUp("slow");
    });
});

Solution

  • #pannel
    {
        position:fixed;
        width:100%;
        height:200px;
        background-color:#ddd;
    }
    


    <div id="pannel"></div>
    


    $(document).keyup(function(e){
    
        if(e.keyCode === 27)
            $("#pannel").slideToggle();
    
    });
    

    Try that?

    fiddle