Domanda

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?

È stato utile?

Soluzione

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

Altri suggerimenti

Try using e.clientX and e.clientY.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top