检测如果浏览器窗口的JavaScript感动? [英] Detecting if the browser window is moved with JavaScript?
问题描述
这是一个演示...我只是好奇,你可以检测,如果窗口已被移动?就像如果你移动火狐/铬/ IE浏览器在你的显示器?我怀疑这一点,但我想看看,因为你可以检查调整大小和焦点/模糊的窗口。
This is for a demo... and i was just curious, can you detect if the window has been moved? Like if you move Firefox/Chrome/IE around your monitor? I doubt it, but i wanted to see since you can check for resize and focus/blurred windows.
推荐答案
我只能想到这个(重型)工作周围,在那里你检查 window.screenX
的和 window.screenY
已经改变了每X毫秒
I can only think of this (heavy) work-around, where you check if window.screenX
and window.screenY
have changed every x milliseconds
var oldX = window.screenX,
oldY = window.screenY;
var interval = setInterval(function(){
if(oldX != window.screenX || oldY != window.screenY){
console.log('moved!');
} else {
console.log('not moved!');
}
oldX = window.screenX;
oldY = window.screenY;
}, 500);
虽然我不建议这一点 - 它可能是缓慢的,我不知道如果screenX和screenY被所有浏览器都支持
Though I would not recommend this -- it might be slow and I'm not sure if screenX and screenY are supported by all browsers
这篇关于检测如果浏览器窗口的JavaScript感动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!