【发布时间】:2017-02-28 08:38:14
【问题描述】:
这是我在 js 中的代码:
window.onload = function(){
var bsDiv = document.getElementById("box");
var x, y;
// On mousemove use event.clientX and event.clientY to set the location of the div to the location of the cursor:
window.addEventListener('mousemove', function(event){
x = event.clientX;
y = event.clientY;
if ( typeof x !== 'undefined' ){
bsDiv.style.left = x + "px";
bsDiv.style.top = y + "px";
}
}, false);
}
</script>
我想添加一个函数,如果光标不在屏幕上(或位置为空?)它使元素不可见,然后在光标重新输入时使其重新可见
【问题讨论】:
-
通常
mousemove事件不会在鼠标离开屏幕时触发 -
已发布 jQuery 答案over there
标签: javascript jquery html