JS获取DIV在BODY内的绝对坐标
function getAbsPoint(e)
{
var x = e.offsetLeft, y = e.offsetTop;
while(e=e.offsetParent)
{
x += e.offsetLeft;
y += e.offsetTop;
}
alert("x:"+x+","+"y:"+y);
}
方法2:
function getAbsPoint(obj)
{
var x,y;
oRect = obj.getBoundingClientRect();
x=oRect.left
y=oRect.top
alert("("+x+","+y+")")
}
JS中获得窗口属性的方法
1。获得屏幕的分辨率:
screen.width
screen.height
2。获得窗口大小:
document.body.clientWidth
document.body.clientHeight
3。获得窗口大小(包含Border、Scroll等元素)
document.body.offsetWidth
document.body.offsetHeight
方法二
$.getAbsPos = function(pTarget){
pTarget = JObj.$(pTarget);
if(!pTarget.getBoundingClientRect){
var x_ = y_ = 0;
while(pTarget.offsetParent){
x_ += pTarget.offsetLeft;
y_ += pTarget.offsetTop;
pTarget = pTarget.offsetParent;
}
x_ += pTarget.offsetLeft;
y_ += pTarget.offsetTop;
return {x:x_,y:y_}
}else{
var body = document.compatMode == 'CSS1Compat' ? document.documentElement : document.body;
var rect = pTarget.getBoundingClientRect()
return {x:rect.left + body.scrollLeft,y:rect.top + body.scrollTop};
}
}