function aim() {
var mousex = ?
}
<div class="gameArea" onmousemove="aim();"> </div>
Run Code Online (Sandbox Code Playgroud)
我找不到如何在javascript中获取onmousemove事件的鼠标坐标.
小智 9
var guide = null;
function aim(event) {
if(window.event)
event = window.event; //grrr IE
var mousex = event.clientX - guide.offsetLeft;
alert('mouse x' + mousex)
}
function init() {
guide = document.getElementById("guide")
guide.onmousemove = aim;
}
<body onload="init();">
Run Code Online (Sandbox Code Playgroud)
这似乎适用于两种浏览器.我不能做onmousemove ="aim();" 在HTML中,因为它没有传递mousemove事件对象.