如何使用javascript / jquery检查鼠标是否退出浏览器窗口? [英] How can I check if the mouse exited the browser window using javascript/jquery?

查看:129
本文介绍了如何使用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.

这篇关于如何使用javascript / jquery检查鼠标是否退出浏览器窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆