在Firefox中捕捉鼠标移动

Capturing mouse movements in Firefox

本文关键字:鼠标 移动 Firefox      更新时间:2023-09-26

我正在编写一款游戏,需要在Firefox中捕捉鼠标移动。这是我的代码:

document.onmousemove = function(e) {
    mouseState.x = e.x;
    mouseState.y = e.y;
}

它在Chrome/IE中正常工作,但在Firefox中似乎不起作用。当我做console.log(mouseState.x)时,它返回为undefined

我需要做什么修改才能让Firefox捕捉鼠标移动?

您应该使用clientXclientY

    Firefox文档
  • w3specs

当我们有clientX/y时,没有人能解释为什么我们需要x/y。Firefox的对这个属性对的处理是迄今为止最合理的(删除了it-gdoron)。

怪异模式

尝试使用e.clientXe.clientY