开发者

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({ 开发者_Go百科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");
    });
});


#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


Try this with keyup event

$(function(){

  $(document).keyup(function(e){

    if(e.which == 27)
    {
      $("div.slider-panel").slideUp("slow");
    }
  });
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜