0

I'm making a ray-caster in JavaScript. How could I track Mouse X and Mouse Y? I've looked around but could not find anything that says anything about this specific situation..

ChinDaMay
  • 204
  • 1
  • 11

1 Answers1

2

try

function getPosition(event) {
  var x = event.offsetX; //event.clientX
  var y = event.offsetY; //event.clientY
  var positionText= "X: " + x + ", Y: " + y;
  document.getElementById("result").innerText = positionText;
}
#content-area{
  width:400px;
  height:100px;
  background-color:red;
}
<span id="result"></span>
<div id="content-area" onmousemove="getPosition(event)">

</div>
mehmetx
  • 850
  • 6
  • 6