How can I trigger a function when my mouse is leaving the viewport?
I listen to the "mouseleave" event from my "html". But in firefox, "mouseleave" also be triggered on two circumstances. 1. is when the alert popup (I solve it now by add the blur/focus listener) 2. when I right click on the page, and the mouse move to the showup menu.
It seems like firefox see this behavior as "mouseleave", even my mouse is still in the page.
here is my code.
$('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);
}
});
How can I solve this problem ? thanks