代码之家  ›  专栏  ›  技术社区  ›  eozzy

按键事件

  •  0
  • eozzy  · 技术社区  · 15 年前

    单击放大的图像时,此函数返回缩略图视图。。。。

    $('#wrapper > img').live('click',function(){
        $this = $(this);
        $('#description').empty().hide();
    
        $('#thumbsWrapper').css('z-index','10')
        .stop()
        .animate({'height':'100%'},speed,function(){
            var $theWrapper = $(this);
            $('#panel').css('height','0px');
            $theWrapper.css('z-index','0');
            /* 
            remove the large image element
            and the navigation buttons
             */
            $this.remove();
            $('#prev').hide();
            $('#next').hide();
        });
    });
    

    非常感谢

    2 回复  |  直到 15 年前
        1
  •  3
  •   Robert    15 年前

    $('#wrapper > img').live('keydown keypress', function(e) {
        if (e.keyCode == 27)  {// Check if the keycode is 27, ie ESCAPE
            do your thing here
        }
    
        2
  •  4
  •   Community CDub    5 年前

    keyup 事件到 document 当页面加载时,检查是否按了ESC。

    http://jsfiddle.net/AXMGM/

    $(document).keyup(function( event ) {
        if(event.which === 27) {
            // Run your code to hide the element
            //   and perhaps first check to see if it needs to be done.
        }
    });
    

    jQuery规范化 event.which 这样它就可以代替 charCode keyCode .

    从文件中-

    event.which 正常化event.keyCode 以及event.charCode. 建议观看event.which 对于键盘键输入。。。

    推荐文章