js获取鼠标位置

 

 

//获取鼠标位置
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 };
}
var obj=getMousePos(event);
var Mousex=obj.x;//横坐标
var Mousey=obj.y;//纵坐标

 

posted @ 2017-05-08 11:45  my-WEB  阅读(442)  评论(0编辑  收藏  举报