开发者

keyboard scrolling on focused div in webkit

I've got this little jquery plugin. There are some images in a vertically scrollable div. I c开发者_StackOverflowan click on this div and scroll it by using arrow keys.

If you take a look at this example, you can see that I want observe if arrow key right/left is pressed and if so, jump to the next image. In Firefox and IE, the keyup() event is being called, and in safari and chrome it's not.

I have encountered several strange scrolling and focus behaviours in webkit browsers, but I don't know why the keyup() event is not being fired. If you have any idea, please let me know.


Just add the tabindex attribute to your div-element and it will work. This is kind of a hack to make an otherwise not focusable element focusable, just like any input or button.

Depending on the value given to tabindex, it will behave diffrently:

  • 0 will allow you to focus the element with the keyboard arrows and tab key
  • -1 will disable tabbing, but it will still be focusable
  • Anything greater then 0 will allow you prioratize tab focusing, where 1 has the highest priority

I've updated the jsFiddle demo accordingly.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜