在 Opera 中使用 jquery 为元素分配动态光标样式
我试图在鼠标悬停在元素上时动态更改光标样式。 光标应该是“移动”或“默认”,具体取决于方法返回的布尔值。 代码是这样的:
$("#elemId").mousemove(function(event) {
if(cursorShouldBeMove()) {
$(this).css({'cursor':'move'});
} else {
$(this).css({'cursor':'default'});
}
}
这段代码在 IE8、FF3、Chrome 和 Safari 中就像一个魅力。 只有 Opera 未能正确处理它。
我正在使用 Opera 9.6.4
有谁知道如何解决这个问题吗?
我准备了样品进行测试;
var cursorStatus = true;
setInterval(function() { cursorStatus = !cursorStatus; }, 500);
function cursorShouldBeMove() {
return cursorStatus;
}
$(function() {
$("#elemId").mousemove(
function(event) {
$(this).css("cursor", cursorShouldBeMove() ? "move" : "default");
}
);
});
如果将鼠标从 #elemId 外部移动到内部几次,您将看到光标会发生变化。 但是,如果您将鼠标放置在 #elemId 中并移动鼠标,光标不会改变。
代码非常简单。 我认为这是 Opera 的一个错误。
我还测试了这段代码;
- Firefox 3.5.1(有效)
- Internet Explorer 7(有效)
- Google Chrome 2.0(有效)
- Safari 3.2(有效)
(Windows 版本)
I'm trying to dynamically change the cursor style when the mouse is over an element. The cursor should be either "move" or "default" depending on a boolean returned by a method.
The code is something like this:
$("#elemId").mousemove(function(event) {
if(cursorShouldBeMove()) {
$(this).css({'cursor':'move'});
} else {
$(this).css({'cursor':'default'});
}
}
This code works like a charm in IE8,FF3,Chrome and Safari.
Only Opera fails to handle it correctly.
I'm using Opera 9.6.4
Does anyone have an idea how to solve this?
I prepared a sample for testing;
var cursorStatus = true;
setInterval(function() { cursorStatus = !cursorStatus; }, 500);
function cursorShouldBeMove() {
return cursorStatus;
}
$(function() {
$("#elemId").mousemove(
function(event) {
$(this).css("cursor", cursorShouldBeMove() ? "move" : "default");
}
);
});
If you move your mouse from outside of #elemId to inside of it for a few times you will see that the cursor will change. But if you position your mouse in #elemId and move your mouse, cursor not changes.
The code is very simple. I think it's a bug of Opera.
I tested this code also with;
- Firefox 3.5.1 (worked)
- Internet Explorer 7 (worked)
- Google Chrome 2.0 (worked)
- Safari 3.2 (worked)
(Windows versions)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Opera 的光标真的很有趣。 我发现您必须将鼠标移到元素上两次才能真正起作用。
可以看到这里你需要将鼠标悬停在Hello World上两次才能使光标发生变化。
此处描述了相同的问题
Opera is real funny with cursors. I find that you have to move the mouse over the element twice before it actually works.
Can see here that you need to hover over the Hello World twice to get the cursor to change.
Same issue described here