javascript 鼠标定位

来源:互联网 发布:八爪鱼软件是什么 编辑:程序博客网 时间:2024/05/29 09:22
//鼠标的绝对定位
function mousePosition(ev){
if(!ev) ev=window.event;
    if(ev.pageX || ev.pageY){
        return {x:ev.pageX, y:ev.pageY};
    }
    return {
        x:ev.clientX + document.documentElement.scrollLeft - document.body.clientLeft,
        y:ev.clientY + document.documentElement.scrollTop  - document.body.clientTop
    };
}