简体   繁体   English

检测鼠标是否不在iframe中的元素上

[英]Detect if the mouse is not over an element in an iframe

I want to be able to detect if the mouse is over a certain div. 我希望能够检测鼠标是否在某个div上。 So I do this 所以我这样做

if ($('#mydv').is(':hover')) {
    //doSometing
});

how do I detect if the mouse in not over the div? 如何检测鼠标是否不在div上? Also I read that this might not work if the element is an iframe. 我也读到,如果元素是iframe,这可能不起作用。 Is there a way to make this work in an iframe as well? 有没有办法在iframe中也能完成这项工作?

Use hover() and flags like 使用hover()和类似的标志

var isOver = false;
$('#mydv').hover(function() {
    isOver = true;
}, function() {
    isOver = false;
});
. 
.
.
//elsewhere in your code you can use isOver to know whether the cursor is over or not

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM