js鼠标事件定位 简单

1. 通过触发某事件,该事件相对document左上角的位置:

BasicUtils.event.getPosition = function(e) {

    e = e || window.event;

    var pos = {};

    if(typeof e.pageX !== "undefined") {

       return {x: e.pageX, y: e.pageY}

    }

    return {

       x: e.clientX + (document.body.scrollLeft || document.documentElement.scrollLeft) ,

       y: e.clientY + (document.body.scrollTop || document.documentElement.scrollTop)

   }

}

原文地址:https://www.cnblogs.com/chyong168/p/2256126.html