关于浏览器获取鼠标的位置

加上了滚动高度

function getMousePos(event) {

        var e = event || window.event;

        var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;

        var scrollY = document.documentElement.scrollTop || document.body.scrollTop;

        var x = e.pageX || e.clientX + scrollX;

        var y = e.pageY || e.clientY + scrollY;

        /*alert('x: ' + x + '\ny: ' + y);*/

        return { 'x': x, 'y': y };

    }

你可能感兴趣的:(关于浏览器获取鼠标的位置)