代码之家  ›  专栏  ›  技术社区  ›  zmbq

鼠标光标在鼠标移动之前不可见(在chrome中)

  •  3
  • zmbq  · 技术社区  · 6 年前

    我有一个HTML页面,鼠标光标设置为 none . 在某些情况下,我把它设为 crosshair . 不幸的是,直到用户真正移动鼠标,光标才显示出来。如果未移动鼠标,则光标保持不可见。

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

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

    2 回复  |  直到 6 年前
        1
  •  1
  •   Shahar    6 年前

    退房 This answer first ,可能就是你要找的。如果没有,我会尝试手动触发事件。我不确定这是否有效,因为即使在触发事件之后,也不能保证浏览器会重新绘制鼠标光标:

    // 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.
    

    如果这不起作用,您可能想用其他鼠标事件来测试它。

        2
  •  -3
  •   Zlerp    6 年前

    尝试 cursor: default;

    光标只应设置为 none 如果你不想光标出现。

    一定有什么东西压倒了 pointer 属性在页面的某个级别。也许在 <body> 或在 <html> 或者父包装。