当鼠标光标离开窗口时如何显示警报

时间:2015-09-30 12:44:15

标签: javascript jquery

我想在鼠标离开窗口时显示警告。像http://ezwebsitebiz.com/testing-content/

一样

我想在jquery中这样做。它是如何实现的

1 个答案:

答案 0 :(得分:0)

var currentMousePos = { x: -1, y: -1 };

        jQuery(document).mousemove(function(event) {

            currentMousePos.x = event.pageX;

            currentMousePos.y = event.pageY;

        });


jQuery(document).mouseleave(function() {

            var window_width = jQuery(window).width();

            var window_height = jQuery(window).height();



            if((currentMousePos.x < window_width) && (currentMousePos.y > 50))

                return true;

           alert(currentMousePos.x.toString());


        })

用弹出窗口或花式框替换警告消息