日期:2014-05-16  浏览次数:20316 次

JS取X和Y轴

取画面的控件的绝对X,Y坐标.


调用:point.Y.call(this,document.getElementById("ID"));

function point_JS() {
this.X = function(obj) {
var curleft = 0;

if (obj.offsetParent) {
   while (obj.offsetParent) {
    curleft += obj.offsetLeft;
   obj = obj.offsetParent;
   }
} else if (obj.x) curleft += obj.x;
return curleft;
};
this.Y = function(obj) {
var curtop = 0;
if (obj.offsetParent) {
   while (obj.offsetParent) {

    curtop += obj.offsetTop;
    obj = obj.offsetParent;
   }
} else if (obj.y) curtop += obj.y;
return curtop;
};
}
var point = new point_JS();