在浏览器中,我试图确定代表鼠标位置的点是否在我称之为"外部区域"的位置.例如,在附加的图像中,外部区域是具有蓝色背景的区域.
替代文字http://i34.tinypic.com/r8grwz.png
在代码和图像中,W代表浏览器视口的宽度,而H代表高度,而x代表鼠标位置
现在,我正在使用这段代码来做到这一点:
if (((x>0 && x<w1) || (x>w2 && x<W))
||
((x>w1 && x<w2) &&
((y>0 && y<h1) || (y>h2 && y<H))
))
console.log("we are in the outer area")
Run Code Online (Sandbox Code Playgroud)
虽然它按原样工作,但我想知道是否有更好的方法呢?