按键事件

发布于 2024-09-14 10:16:38 字数 639 浏览 4 评论 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”?

非常感谢

This function returns to the thumbnail view when clicked on the enlarged image....

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

... besides click, I want it also close on keypress or just 'Esc' if possible?

Many thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ぶ宁プ宁ぶ 2024-09-21 10:16:38

当页面加载时,我会将 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 进行键盘按键输入...

I'd bind a keyup event to the document when the page loads, which checks if ESC was pressed.

Try it out: 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 normalizes the event.which such that it can be used in place of charCode and keyCode.

From the docs -

event.which normalizes event.keyCode and event.charCode. It is recommended to watch event.which for keyboard key input...

柠檬色的秋千 2024-09-21 10:16:38

如果你想绑定转义,你可以检查 keypress/keydown 是否是转义键,如果是,则使用它,否则不执行任何操作。

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

If you want to bind escape you can check on keypress/keydown if the key is escape, and if so, use it, otherwise do nothing with it.

$('#wrapper > img').live('keydown keypress', function(e) {
    if (e.keyCode == 27)  {// Check if the keycode is 27, ie ESCAPE
        do your thing here
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文