//取得控件得绝对位置(1)
<script language="javascript">
function getoffset(e)
{
var t=e.offsetTop;
var l=e.offsetLeft;
while(e=e.offsetParent)
{
t+=e.offsetTop;
l+=e.offsetLeft;
}
var rec = new Array(1);
rec[0] = t;
rec[1] = l; return rec
} //获得控件的绝对位置(2)
oRect = obj.getBoundingClientRect();
oRect.left
oRect.top
<script language="javascript">
function getoffset(e)
{
var t=e.offsetTop;
var l=e.offsetLeft;
while(e=e.offsetParent)
{
t+=e.offsetTop;
l+=e.offsetLeft;
}
var rec = new Array(1);
rec[0] = t;
rec[1] = l; return rec
} //获得控件的绝对位置(2)
oRect = obj.getBoundingClientRect();
oRect.left
oRect.top
============================
function Rect(){
this.width=0;
this.height=0;
this.left=0;
this.top=0;
this.right=0;
this.bottom=0;
}
Rect.prototype.Cal=function () {
this.right=this.left+this.width;
this.bottom=this.top+this.height;
}
Rect.prototype.ContaintPoint=function (x,y){
if(x>=this.left && x<=this.right && y>=this.top && y<=this.bottom) return true;
return false;
}
Rect.prototype.BeCoverBy=function (rectSrc){
return rectSrc.ContaintPoint(this.left,this.top) ||
rectSrc.ContaintPoint(this.left,this.bottom) ||
rectSrc.ContaintPoint(this.right,this.top) ||
rectSrc.ContaintPoint(this.right,this.bottom) ||
this.ContaintPoint(rectSrc.left,rectSrc.top) ||
this.ContaintPoint(rectSrc.right,rectSrc.top) ||
this.ContaintPoint(rectSrc.left,rectSrc.bottom) ||
this.ContaintPoint(rectSrc.right,rectSrc.bottom);
}
function getElementRect(obj){
var e=obj;
var pos=new Rect;
pos.width=obj.offsetWidth;
pos.height=obj.offsetHeight;
pos.left=obj.offsetLeft;
pos.top=obj.offsetTop;
while(e=e.offsetParent){
pos.left+=e.offsetLeft;
pos.top+=e.offsetTop;
}
pos.Cal();
return pos;
}
screenTop 获取浏览器客户区左上角相对于屏幕左上角的 y 坐标。
这个?
好像是这个
可是<a href="JavaScript:alert(this.screenLeft);">测试</a>怎么是0?ttyp 知道怎么取得屏幕坐标吗?
window.screenTop再加上它的相对位置
刚才一个朋友理解错了
偶说的popup是window.createPopup…………faint,是偶的错,没说明白
popup Object 没有位置相关属性和方法。只有在SHOW时确定它的位置。
这个偶知道D就是…………偶想在一个连接旁边显示这个popup object
popup object的定位方式是全屏幕定位链接的定位方式是网页定位……这两个怎么转换?
screenLeft,screenTop是window对象的加上工具栏,菜单烂这些就不对了fason,帮帮忙
============================谢谢heyixiang,希望能顶个答案出来
怎么定位呀?无法计算当前元素的屏幕位置啊