如何使用javascript / jquery检查鼠标是否退出浏览器窗口?

问题描述:

我需要一种方法来检查鼠标是否在浏览器窗口之外。问题是鼠标RAPIDLY移动到浏览器窗口外部(我的元素靠近边缘)时,mouseout事件(或mousemove)不会被触发。我想,解决我的问题的最好方法是检查一个计时器,如果鼠标在窗口内或没有,但我还没有找到一种方法来做到这一点,因为我需要一个事件来触发,以获得鼠标坐标。

I need a way to check and see if the mouse is outside the browser window. The problem is that the mouseout event (or mousemove) isn't triggered when the mouse RAPIDLY moves outside the the browser window (my element is close to the edge). I figured the best way to solve my problem is to check on a timer if the mouse is inside the window or not, but I haven't found a way to do that, since I need an event to fire in order to get the mouse coordinates.

我是一个javascript / jquery新手,但似乎应该有办法做到这一点,但我绝对没有能够找到它。也许我可以强制一个鼠标事件触发,看看是否有任何xy值?任何想法我该怎么做?

I'm a javascript/jquery newbie, but it seems like there should be a way to do this but I definitely haven't been able to find it so far. Maybe I could force a mouse event to trigger and see if there's any xy value? Any idea how I could do that?

提前感谢

p>似乎像 @Joshua Mills 在这里解决了这个问题:

Seems like @Joshua Mills solved this problem here:

  • How can I detect when the mouse leaves the window?

虽然它从未被正式选为答案。

Although it was never officially selected as an answer.