当我的鼠标离开视口时如何触发功能?
我从“html”中收听“mouseleave”事件。但是在firefox中,“mouseleave”也是在两种情况下触发的。1. 是弹出警报的时候(我现在通过添加模糊/焦点侦听器来解决它) 2. 当我右键单击页面时,鼠标移动到显示菜单。
似乎 Firefox 将此行为视为“mouseleave”,即使我的鼠标仍在页面中。
这是我的代码。
$('html').bind('mouseleave',bouncehandler);
var visted = 1;
var bouncehandler = function(e){
var yheight = $(window).height();
if(e.pageX<$('body').width() && e.pageY < yheight ){
alert('leaving');
$('html').unbind('mouseleave',bouncehandler);
}
}
$(window).blur(function(){
$('html').unbind('mouseleave',bouncehandler);
}).focus(function(){
if(visited){
$('html').bind('mouseleave',bouncehandler);
}
});
我怎么解决这个问题 ?谢谢