如何在 Opera 中聚焦用于键盘滚动的 div
我有一个类似灯箱的 div,它出现在页面上以呈现可滚动的内容。在 FF、IE 和 Chrome 中,允许用户使用箭头和 pagedown/up 键滚动灯箱就像为其分配 tabindex 并调用 .focus() 一样简单。
在 Opera 中,.focus() 不执行任何操作,制表符/箭头/页面键将继续作用于背景页面中的任何制表符元素。
这是一个小提琴来说明问题: http://jsfiddle.net/9W943/5/
我有看过很多关于如何聚焦 div 的例子,但似乎没有人承认 tabindex 方法在 Opera 中不起作用。有什么方法可以强制 Opera 聚焦灯箱吗?如果做不到这一点,最好的解决方法是什么 - 监听关键事件,然后“手动”滚动灯箱? (或者我可以重定向事件吗?)
我尝试在灯箱上调用 .click() ,并创建+调度一个假点击事件 - 因为键盘滚动在单击后可以正常工作 - 但都不起作用。
我也很好奇为什么非输入元素可聚焦不是标准的,因为它们可以并且确实接收键盘事件!如果不是可以通过键盘进行交互的元素,如何定义焦点元素?
I have a lightbox-like div which appears over pages to present scrollable content. In FF, IE, and Chrome, allowing the user to scroll the lightbox with the arrow and pagedown/up keys is as simple as assigning it a tabindex and calling .focus().
In Opera, .focus() does nothing and tab/arrow/page keys will continue acting on whatever tabstop elements are in the background page.
Here's a fiddle to illustrate the problem: http://jsfiddle.net/9W943/5/
I have seen many examples of how to focus a div, but none seem to acknowledge that the tabindex approach doesn't work in Opera. Is there any way I can force Opera to focus the lightbox? Failing that, what's the best workaround - listen for key events and then "manually" scroll the lightbox? (Or can I redirect the events?)
I have tried calling .click() on the lightbox, and creating+dispatching a fake click event - since keyboard scrolling works correctly after you click it - but neither worked.
Also I am very curious why it's not standard for non-input elements to be focusable, since they can and do receive keyboard events! How do you define a focused element, if not as the element which can be interacted with via the keyboard?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个已知的错误(内部 DSK-269802) - 不幸的是,据我所知,没有很好的解决方法:-/
我昨天自己遇到了这个问题,并且会给这个错误一个“凹凸” - 也许我们可以将它融入到一些- 正在进行的开发工作。我建议您忽略该错误,只像在 Opera 中工作一样编写代码,因为有一天它会的。
This is a known bug (internally DSK-269802) - unfortunately there is no nice workarounds that I know of :-/
I ran into this problem yesterday myself and will give the bug a "bump" - perhaps we can fit it into some on-going development work. I'd recommend that you ignore the bug and just code as if it worked in Opera, because some day it will.