Home > Enterprise >  Get value of mouse Y axis (JavaScript)
Get value of mouse Y axis (JavaScript)

Time:01-08

I am making a game in JavaScript and I would like to define a variable as the Mouse Y axis. Please don't make the code un-necessarily complex if you can help it. That's all

CodePudding user response:

You can use addEventListener for "mousemove", which on each movement of mouse prints out it coordinates:

document.addEventListener("mousemove", () => {
  let mousex = event.clientX; // Gets Mouse X
  let mousey = event.clientY; // Gets Mouse Y
  console.log([mousex, mousey]); // Prints data
});

Code credits: https://www.codegrepper.com/code-examples/javascript/how to get mouse x and y in javascript

  •  Tags:  
  • Related