Javascript pageY issue with Microsoft Edge browser

时光总嘲笑我的痴心妄想 提交于 2019-12-10 09:23:17

问题


I want to create a simple script that will detect if user mouse leave window. Solution is already described here by using mouseout event. The problem with this solution is that it will trigger action also if user goes with mouse to scroller. So I added extra if condition e.pageY < jQuery(window).scrollTop() to this code:

addEvent(document, "mouseout", function(e) {
    e = e ? e : window.event;
    var from = e.relatedTarget || e.toElement;
    if ((!from || from.nodeName == "HTML") && e.pageY < jQuery(window).scrollTop()) {
        alert("left window");
    }
});

It works fine in all browsers, excepting Microsoft Edge. In Edge e.pageY won't be necessary 0 or -1,-2... as in other browsers but it will be 50,34,... (depends how fast you move mouse).

I am wondering if there is any simple solution to this problem.

来源:https://stackoverflow.com/questions/33157067/javascript-pagey-issue-with-microsoft-edge-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!