2013-03-18 47 views
6

我在改变光标的html元素上按住鼠标。现在,如果用户在按下鼠标按钮的同时点击某个键,则会为该元素指定另一个光标。这对于Mozilla立即改变游标而不是在chrome中工作得很好。在chrome中,我需要移动光标至少一个像素以使新光标可见。请注意,只有在按下鼠标按钮时才会发生这种情况。如果不是,则光标根据需要立即切换。任何想法如何解决这个问题?当鼠标关闭时,CSS光标变化不起作用

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

但不管怎么说,任何想法,使其仍在工作,因为没有修复了没有?

这里的小姐行为样本:JSFiddle Sample,此代码:

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"; 
}); 
+0

花式制作小提琴? – 2013-03-18 13:59:28

+0

向我们展示您的代码HTML/JS/CSS – Lowkase 2013-03-18 14:04:57

+0

您是否试图通过使用javascript添加删除类来完成此操作? 另外..你为什么使用内联样式? Regards, – Guillermo 2013-11-27 16:53:35

回答

1

这是为我工作中的铬,而不必移动鼠标:

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/

还是我想念什么?

相关问题