我有一个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/ –