检测鼠标是否未在iframe中的某个元素上

Detect if the mouse is not over an element in an iframe

本文关键字:元素 iframe 鼠标 是否 检测      更新时间:2023-09-26

我想能够检测鼠标是否在某个div上。所以我做了这个

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

如何检测鼠标是否未在div上方?我还读到,如果元素是iframe,这可能不起作用。有没有办法在iframe中也能做到这一点?

使用悬停((和等标志

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