首页 > 解决方案 > 在鼠标移动之前鼠标光标不可见(在 Chrome 中)

问题描述

我有一个 HTML 页面,其中鼠标光标设置为none. 在某些情况下,我将其设置为crosshair. 不幸的是,在用户实际移动鼠标之前,不会显示光标。如果鼠标没有移动,光标将保持不可见。

如何告诉浏览器在不移动鼠标的情况下重绘光标?

编辑:可能的重复不是重复的。显然这个问题在 Firefox 和 Internet Explorer 中得到了解决,但在 Chrome 中没有得到解决。

标签: htmlcss

解决方案


先看看这个答案,它可能就是你要找的。如果没有,我会尝试手动触发事件。我不确定这会起作用,因为即使在触发事件之后,它也不能保证浏览器会重绘鼠标光标:

// listen to mouse move event
window.onmousemove = function(e) {
    console.log('mouse moved.', e);
};

// create and trigger the event
var event = new Event('mousemove');
window.dispatchEvent(event);

// should now see 'mouse move.' in the console.

如果这不起作用,您可能需要使用其他鼠标事件进行测试。


推荐阅读