键盘绑定在Firefox中不起作用 [英] keyup bindings not working in Firefox

查看:76
本文介绍了键盘绑定在Firefox中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以在这里看到我的项目-

You can see my project here -

http://www.inluxphoto.com/custom/jsgallery/index.php

我试图使左右箭头键移动幻灯片.完全按照jqueryfordesigners.com首页上的说明进行操作,我就能使它在所有浏览器中都能正常工作(很抱歉,我只允许一个链接).

I am attempting to make the left and right arrow keys move the slideshow. I was able to get it to work in all browsers by following exactly the instructions on the front page of jqueryfordesigners.com (sorry I am only allowed one link).

但是,必须取消绑定键,直到动画完成,这样用户才能快速双击该键,这会中断显示.这导致我使用以下功能-

However, it is necessary that the keyup be unbinded until the animation completes, so the user cannot do a quick double tap of the key, which breaks the show. This led me to the following function -

function keyCommands() {

  //Bind Keys according to keyAssignments
  function keyCommandBind() {
   $(document.documentElement).bind('keyup', keyAssignments)   
  }

  //Bind functions to specific keys
  function keyAssignments() {

   if (event.keyCode == 37) {
    leftArrow();
   }

   if (event.keyCode == 39) {
    rightArrow();
   }

   if (event.keyCode == 32) {
    spaceBar();
   }

  }

  function leftArrow() {
         //unbind, do stuff, rebind
  }

  function rightArrow() {
          //unbind, do stuff, rebind
  }

  function spaceBar() {
          //unbind, do stuff, rebind
  }

  keyCommandBind();

 }

这适用于除Firefox&以外的所有浏览器.卡米诺. Firebug告诉我event(即event.keyCode)未定义.是的,没有定义,我理解.但是我不明白为什么,如果未定义它在所有其他浏览器中都能正常工作.

This works in all browsers except Firefox & Camino. Firebug tells me event (ie event.keyCode) is not defined. That's true, it's not defined, and I understand that. However I don't understand why, if it's not defined, does it work in all other browsers.

我该如何适当地定义它?或者,我做错了吗?

How can I appropriately define this? Or, am I doing it wrong?

非常感谢您的帮助!

推荐答案

尝试将keyAssignments声明为function keyAssignments(event) {.我不确定为什么它会在某些情况下起作用,但在其他情况下却不起作用,也许它们有一个保留变量,默认情况下会在keyup事件中冒泡?

Try declaring keyAssignments as function keyAssignments(event) {. I'm not sure why it would work in some but not others, maybe they have a reserved variable that bubbles with the keyup event by default?

这篇关于键盘绑定在Firefox中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆