CSS光标改变不工作时,鼠标是向下的



我将鼠标按在html元素上,这会改变光标。现在,如果用户在按下鼠标按钮的同时点击了一个键,我将为元素分配另一个光标。这在Mozilla上工作得很好,它会立即改变光标,但在chrome上不行。在chrome中,我需要移动光标至少一个像素,使新的光标可见。注意,这只会在按下鼠标按钮时发生。如果没有,光标会根据需要立即切换。有什么好办法吗?

更新:我刚刚发现这似乎是WebKit中的一个bug:https://bugs.webkit.org/show_bug.cgi?id=53341

但是无论如何,有没有办法使它仍然工作,因为还没有修复出来?

下面是遗漏行为的示例:JSFiddle示例代码: html:

<div id="test1" style="background:blue;width:200px;height:200px;color:white">Case #1 -   cursor not changing for mousedown before moving it (Press mouse - nothing happens. Then hold mouse and move)</div>
<div id="test2" style="background:red;width:200px;height:200px;color:white">Case #2 - cursor not changing for mousedown before moving it when pressing a key (Press mouse, then click any key - Nothing happens. Then hold mouse and move)</div>

js:

var el1 = document.getElementById("test1");
var el2 = document.getElementById("test2");
el1.addEventListener("mousedown", function() {
    el1.style.cursor = "move";
});
document.addEventListener("keydown", function() {
    el2.style.cursor = "move";
});

这是工作为我在chrome无需移动鼠标:

var el1 = document.getElementById("test1");
var el2 = document.getElementById("test2");
el1.addEventListener("mousedown", function() {
    el1.className += ' cursormove';  
});
document.addEventListener("keydown", function() {
    el1.style.cursor = "pointer";
});

.cursormove {cursor:move;}
http://jsfiddle.net/ntdap5hf/4/

还是我错过了什么?

最新更新