现在的位置: 首页 > 综合 > 正文

js获取鼠标点击位置(界面的位置,可以使用top和left直接定位的)

2018年02月04日 ⁄ 综合 ⁄ 共 594字 ⁄ 字号 评论关闭

function getPointerPosition(e){

       var obj = e.currentTarget||document.activeElement;
       var position = {

              //clientY ie和firefox都支持,表示鼠标到页面顶的距离,但是不包括滚动条里面的距离

              //pageY firefox支持 表示鼠标到页面顶的距离,包括滚动条里面的距离

              //document.documentElement.scrollTop   firefox支持的 就是滚动条上面的看不到局域的高度

              //document.body.scrollTop   ie支持的  就是滚动条上面的看不到局域的高度
              left:e.pageX || (e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft)),
              top:e.pageY || (e.clientY + (document.documentElement.scrollTop || document.body.scrollTop))
           };
       return position;
}

抱歉!评论已关闭.