获取鼠标点击位置坐标

    function getMousePos(event) {
        //兼容IE:event || window.event;
        var e = event || window.event;
        //页面滚动位移: chrome是document.body.scrollLeft,IE是document.documentElement.scrollLeft
        var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
        var scrollY = document.documentElement.scrollTop || document.body.scrollTop;
        //浏览器窗口的坐标:e.clientX
        //Firefox支持属性pageX,与pageY属性,这两个属性已经把页面滚动计算在内了
        var x = e.pageX || e.clientX + scrollX;
        var y = e.pageY || e.clientY + scrollY;
        //alert('x: ' + x + '\ny: ' + y);
        console.log("X:" + x + " Y:" + y);
        return {'x': x, 'y': y};
    }

 

posted @ 2018-07-10 14:56  寂寞之砂  阅读(529)  评论(0编辑  收藏  举报