Skip to content

Instantly share code, notes, and snippets.

@andyg1
Created January 25, 2016 12:45
Show Gist options
  • Save andyg1/1b95e4e5590e49394624 to your computer and use it in GitHub Desktop.
Save andyg1/1b95e4e5590e49394624 to your computer and use it in GitHub Desktop.
Cross-browser, mouse leaving the window event
function addEvent(obj, evt, fn) {
if (obj.addEventListener) {
obj.addEventListener(evt, fn, false);
}
else if (obj.attachEvent) {
obj.attachEvent("on" + evt, fn);
}
}
addEvent(document, "mouseout", function(e) {
e = e ? e : window.event;
var from = e.relatedTarget || e.toElement;
if (!from || from.nodeName == "HTML") {
alert('mouse gone');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment