获取鼠标X、Y轴坐标

//获取鼠标X、Y轴坐标
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 getX(ev){ 
    ev = ev || window.event; 
    var mousePos = mousePosition(ev); 
	var x = mousePos.x;
	return x;
} 

function getY(ev){ 
    ev = ev || window.event; 
    var mousePos = mousePosition(ev); 
	var y = mousePos.y;
	return y;
} 


你可能感兴趣的:(JavaScript)