私はdiv
にonmousemove
を持っています。これはオブジェクトをカーソルに追従させるために使用します。このdiv
内には、別のdiv
とonmouseleave
があります。問題は、onmouseleave
がオブジェクトからのカーソルを非常に高速に移動する場合にのみ機能するということです。ただし、onmousemove
を削除すると、onmouseleave
が正しく機能し始めます。 onmousemove
とonmouseleave
を同時に動作させるにはどうすればよいですか?onmouseleaveはonmousemove内で動作しません
HTML:
<body>
<div onmousemove="cursorMove(event)" id="main">
<p id="title">...</p>
<div onmouseleave="gameOver()" id="light"></div>
<div id="cursor"></div>
</div>
<button onclick="moveLight()">move</button>
<button onclick="startGame()">start</button>
<script src="js/javascript.js"></script>
</body>
はJavaScript
function cursorMove(event) {
document.getElementById("cursor").style.top = event.clientY - 14;
document.getElementById("cursor").style.left = event.clientX - 14;
document.getElementById("cursor").style.opacity = '1';
}
function gameOver() {
console.log("Game Over");
document.getElementById("light").style.top = 245 + 'px';
document.getElementById("light").style.left = 238 + 'px';
document.getElementById("title").style.opacity = '1';
document.getElementById("title").innerHTML = 'Enter the light';
gameActive = false;
}
私はインラインイベントをaddEventListnerで置き換えようとしましたが、残念なことに違いはありませんでした。 –
例を変更しました:https://jsfiddle.net/4hkkm7k5/1/ –