简体   繁体   English

鼠标悬停在元素上时,使用什么事件代替onmouseout?

[英]What event to use instead of onmouseout to run when mouse is not over the element?

i want to run a script when i'm not hovering an element. 我想在没有悬停元素的情况下运行脚本。 It's some kind of deactivating something else that was run previously in 'onmouseover' event. 这是某种以前在'onmouseover'事件中运行的其他东西的停用。 So I'm using onmouseout event to run this script, however , the problem is that if i don't hover the element and then leave it , the script just don't run. 所以我使用onmouseout事件来运行这个脚本,但问题是 ,如果我不悬停元素然后离开它,脚本就不会运行了。 this happens if eg hover the element too fast or the window loses focus . 如果例如将元素悬停得太快或窗口失去焦点,就会发生这种情况。 How can i solve that? 我怎么解决这个问题?

EDIT: let me illustrate this in another way , what i need is an event to be run when an element isn't touched by mouse. 编辑:让我以另一种方式说明这一点,我需要的是当鼠标未触及元素时要运行的事件。

you can try this, 你可以尝试这个,

<div id="div1" onmouseover="fucntionIn()" onmouseout="functionOut()">"Special Area"</div>
<div id="div2" onmouseover="fucntionOut()">Other area</div>

the logic is to write deactivate code for onmouseover event of other area of the page. 逻辑是为页面其他区域的onmouseover事件编写停用代码。

如果你在整个页面上检测到onmouseover (通过事件冒泡),当它进入一个新元素时,如果你最后观察到的原始元素是当前目标元素的父元素,如果不是,那么你知道它退出了原始DOM节点,即使onmouseout没有触发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当鼠标不在元素上方时,使用onmouseout运行吗? - use onmouseout to run when mouse is not over the element? 当我在javascript中删除鼠标当前位于上方的元素时,会发生onMouseOut事件吗? - Does onMouseOut event occurs when I remove in javascript the element the mouse is currently over? 将鼠标移到某些元素上时Onmouseout是否无法运行? - Onmouseout not to run when moving mouse over to certain elements? 当我将光标移动到元素上而不离开元素时,将调用 onmouseout JavaScript 事件 - onmouseout JavaScript event being called when I move the cursor over an element without going out of the element 当鼠标移过按钮时,如何使用onmouseover和onmouseout来隐藏和取消隐藏按钮? - How to use onmouseover and onmouseout to hide and unhide a button when the mouse goes over it? 当鼠标移到与元素重叠的位置时,请勿触发onmouseout - Don't fire onmouseout when mouse moves to something overlaying the element 当我仍将鼠标悬停在标签上时,会发生onmouseout事件 - onmouseout event happens when I am still hovering over the label 当 hover 超过孩子时防止触发 onMouseOut 事件 - Prevent triggering onMouseOut event when hover over children 使用bodymove事件获取鼠标所在的元素 - get what element the mouse is over with the mousemove event on the body javascript onmouseout也适用于鼠标悬停 - javascript onmouseout works also on mouse over
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM