Javascript 在Firefox中捕捉鼠标移动
我正在写一个游戏,需要在Firefox中捕捉鼠标移动。这是我的代码:Javascript 在Firefox中捕捉鼠标移动,javascript,firefox,onmousemove,Javascript,Firefox,Onmousemove,我正在写一个游戏,需要在Firefox中捕捉鼠标移动。这是我的代码: document.onmousemove = function(e) { mouseState.x = e.x; mouseState.y = e.y; } 它在Chrome/IE中正常工作,但在Firefox中似乎不起作用。当我执行console.log(mouseState.x)时,它返回为undefined 我需要做哪些修改才能让Firefox捕捉鼠标移动?您应该使用clientX和clientY
document.onmousemove = function(e) {
mouseState.x = e.x;
mouseState.y = e.y;
}
它在Chrome/IE中正常工作,但在Firefox中似乎不起作用。当我执行console.log(mouseState.x)
时,它返回为undefined
我需要做哪些修改才能让Firefox捕捉鼠标移动?您应该使用
clientX
和clientY
您应该使用
clientX
和clientY
尝试使用
e.clientX
和e.clientY
尝试使用e.clientX
和e.clientY