如果在基于 Webkit 的浏览器中不移动指针,则鼠标光标不会改变
假设我们有如下简单的 jQuery 代码:
var $document = $(document);
$document.ready(function() {
var $test = $("#test");
$document.keydown(function(e) {
e.shiftKey && $test.css("cursor", "pointer");
});
});
问题是,如果鼠标指针移到 #test
上,WebKit 不会更改 #test
块鼠标光标。块,然后按下 Shift 键。但只要您移动光标,Chrome 和 Safari 就会将光标样式更改为指针 - 与预期完全一致,但无需移动鼠标。这个bug(?)与Firefox无关,我没有在Internet Explorer和Opera下检查它......
那么,有人遇到过同样的麻烦吗?也许有解决方法吗?
提前致谢。
Let's assume that we have simple jQuery code like the following:
var $document = $(document);
$document.ready(function() {
var $test = $("#test");
$document.keydown(function(e) {
e.shiftKey && $test.css("cursor", "pointer");
});
});
The problem is that WebKit does not change the #test
block mouse cursor if the mouse pointer is moved over the #test
block, and the Shift key is pressed then. But as soon as you move the cursor, Chrome and Safari change the cursor style to pointer
- exactly as it's expected but without mouse move. This bug (?) is not relevant to Firefox, and I didn't check it under Internet Explorer and Opera...
So, did anyone have experience with the same trouble? Perhaps, is there a workaround for that?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是当时 webkit 引擎中的一个众所周知的错误,并且没有真正的解决方法。
This is a well known bug in then webkit engine, and there is no real workaround for it.
我在使用 Chromium 11.0.696.65 时遇到了这个问题。我能够用一点延迟的 JavaScript 来解决这个问题。
我试图制作一个电子标牌,它由一个大型 LCD 显示器组成,由一台在 Ubuntu 上运行 Chromium 的小型无盘工业计算机驱动。启动时,它会运行如下内容:
下载的页面有一个 XHR 轮询循环,每当与 id=42 相关的任何更改时,该循环都会接收 JavaScript 对象文字,此时,它会相应地更新显示。 CSS 指定所有元素都应该有一个空白鼠标指针。
问题是,Chrome 正在请求的鼠标指针留在屏幕上。当我移动鼠标时它就消失了。然而,真正的标牌不会附有鼠标,更不用说用户来移动它了。
我添加了以下脚本:
现在,恼人的光标在启动时短暂显示,但一秒钟后消失。然后标志将无光标运行,直到下次启动(几天或几周)。
顺便说一句,
,auto
似乎是另一个 Chromium bug。我发现如果我只输入url(/blankCursor.gif)
,它不会遵守该声明。I had this problem using Chromium 11.0.696.65. I was able to solve it with a little delayed JavaScript.
I was trying to make an electronic sign consisting of a large LCD monitor driven by a small diskless industrial computer running Chromium on Ubuntu. On start up, it runs something like:
The downloaded page has an XHR polling loop which receives a JavaScript object literal whenever anything changes relating to
id=42
, at which time, it updates the display appropriately. There is CSS specifying all elements should have a blank mouse pointer.Problem was, Chrome's request-in-progress mouse pointer was left sitting on the screen. It disappeared as soon as a I moved the mouse. However, the real sign won't have a mouse attached, much less a user to move it.
I added the following script:
Now, the annoying cursor shows up briefly on startup, but vanishes in a second. Then the sign runs cursorless until the next startup (days or weeks).
BTW, the
,auto
appears to be another Chromium bug. I found if I just puturl(/blankCursor.gif)
, it won't honor the declaration.与之前所说的相反,我从 David Becker 那里找到的这个解决方法似乎很有效。 (针对浏览器的修复已在管道中。请参阅 https://bugs.webkit.org /show_bug.cgi?id=101857 )
Contrary to what was said before, this workaround I found from David Becker seems to be effective. (The fixes for the browsers are in the pipe. See https://bugs.webkit.org/show_bug.cgi?id=101857 )
我找到了解决该问题的方法。
如果强制浏览器重排,光标似乎会发生变化。因此,如果您将光标设置在 elem 上,然后调用 elem.scrollTop(或触发重排的任意数量的属性),光标将就地更新。
所以在你的情况下,代码最终将是:
I've found a workaround to the problem.
It seems the cursor is changed if you force the browser to reflow. So, if you set the cursor on
elem
and then callelem.scrollTop
(or any number of properties which trigger a reflow), the cursor will update in place.So in your case the code would end up being: