1

I wanted to find a way to get the position of my mouse without moving it (using "mousemove" eventlistener) , because if the screen gets scrolled without the move of a mouse, the coordinants dont match up.

so i planned on getting it to move via adding the offset, !but only when im not getting the right coordinants! .

window.addEventListener("mousemove", myFunction);

function myFunction() {
//offset Code
}


if( event("mousemove") == active) {
//so if i move the mouse this will be active

} else {
//thus not active (and vice versa)
}
Stu
  • 11
  • 3
  • 1
    probably duplicate of [how to get the mouse position without events without moving the mouse](https://stackoverflow.com/questions/2601097/how-to-get-the-mouse-position-without-events-without-moving-the-mouse) – azbarcea Aug 28 '19 at 23:26
  • 1
    Possible duplicate of [How to get the mouse position without events (without moving the mouse)?](https://stackoverflow.com/questions/2601097/how-to-get-the-mouse-position-without-events-without-moving-the-mouse) – skyline3000 Aug 28 '19 at 23:51
  • Although, the goal is the same. the answer to that question doesnt help my case. and my question is more about the vent listerner – Stu Aug 29 '19 at 00:57

1 Answers1

0

The first argument to an event listener is the Event object. You can check the type of event there.

function myFunction(event) {
    if (event.type == 'mousemove') {
        // some code here
    } else {
        // other code here
    }
}
Barmar
  • 741,623
  • 53
  • 500
  • 612