- function CPos(x,y)
- {
- this.x = x;
- this.y = y;
- }
- function GetObjPos(ATarget)
- {
- var target = ATarget;
- var pos = new CPos(target.offsetLeft, target.offsetTop);
- var target = target.offsetParent;
- while (target)
- {
- pos.x += target.offsetLeft;
- pos.y += target.offsetTop;
- target = target.offsetParent
- }
- return pos;
- }
获取控件的绝对位置(该控件非position:absolute)
最新推荐文章于 2024-07-21 20:14:06 发布
本文介绍了一种使用JavaScript来确定HTML页面中元素的精确位置的方法。通过创建一个简单的坐标类CPos,并利用offsetLeft和offsetTop属性,可以递归地计算出元素相对于页面左上角的实际位置。这种方法对于实现复杂的页面布局或交互式应用非常有用。
5420

被折叠的 条评论
为什么被折叠?



