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..
Asked
Active
Viewed 192 times
1 Answers
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
-
Thanks! That worked! – ChinDaMay Jan 13 '21 at 16:54