1

I'm writing a game and need to capture mouse movements in Firefox. This is my code:

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

it works correctly in Chrome/IE however it doesn't seem to work in Firefox. When I do console.log(mouseState.x) it comes back as undefined.

What modifications do I need to make to get Firefox to capture mouse movements?

James Dawson
  • 5,179
  • 20
  • 70
  • 126

2 Answers2

3

You should use clientX and clientY instead.

Nobody can explain why we need x/y when we have clientX/Y. Firefox’s take on this property pair is by far the sanest(removed it-gdoron).

quirks mode

gdoron is supporting Monica
  • 142,542
  • 55
  • 282
  • 355
1

Try using e.clientX and e.clientY.

Kuba Jagoda
  • 4,088
  • 2
  • 18
  • 20