2010-08-13 69 views
0

该函数返回到放大图像,点击上时,缩略图视图....事件按键时

$('#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(); 
    }); 
}); 

...点击之外,我想这也接近上按键或只是“Esc键”如果可能的话?

非常感谢

回答

3

如果你要绑定逃避您可以检查按键/ KEYDOWN如果关键是逃避,如果是的话,使用它,否则什么都不做吧。

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

我一个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使得它可以代替charCodekeyCode使用。

从文档 -

event.which标准化event.keyCode和event.charCode。建议看键盘按键输入event.which ...