I need to setup an initial state using the cursor position when the user presses a button, then update that state when the cursor moves. Curiously, it seems difficult to get the cursor position outside an event.
I have the following code:
// Here is where I would like to set an initial state but don't know how to get the coordinates
thing.addEventListener('mousemove', function (e) {
// Here is where I update based on new e.clientX and e.clientY
});
The above actually seems to work without even setting the initial state. It seems the mousemove event is fired as soon as I assigned it, even though it perhaps has not moved since the click.
Does anybody know if this is intentional behavior that I can rely on?