获取事件源对象坐标、事件坐标

function GetEvent() 
   if(document.all) // IE 
   { 
       return window.event; 
   } 
   func = GetEvent.caller; // 返回调用本函数的函数 
   while(func != null) 
   { 
       // Firefox 中一个隐含的对象 arguments,第一个参数为 event 对象  
       var arg0 = func.arguments[0]; 
       //alert('参数长度:' + func.arguments.length); 
       if(arg0) 
       { 
           if((arg0.constructor == Event || arg0.constructor == MouseEvent) 
               ||(typeof(arg0) == "object" && arg0.preventDefault && arg0.stopPropagation)) 
           { 
               return arg0; 
           } 
       } 
       func = func.caller; 
   } 
   return null; 

//事件坐标 

function mousePosition(ev){
    if(ev.pageX || ev.pageY){
    return {x:ev.pageX, y:ev.pageY};
    }
    return {
        x:ev.clientX + document.body.scrollLeft - document.body.clientLeft,
        y:ev.clientY + document.body.scrollTop - document.body.clientTop
    }; 
}

//获取事件源对象坐标 

function getpos(evSource) {   

    var t=evSource.offsetTop + evSource.offsetHeight ;  

    var l=evSource.offsetLeft;     

    while(e=e.offsetParent) {  

        t+=evSource.offsetTop;  

        l+=evSource.offsetLeft;  

    }   

}   

posted @ 2010-07-16 10:48  迟追  阅读(553)  评论(0编辑  收藏  举报