相对元素的绝对位置 [英] Absolute position of a relative element

查看:92
本文介绍了相对元素的绝对位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




如何获得相对元素的绝对位置?


我们动态创建一个包含多个片段的页面彼此之间订购的相对比较好。在这些段中,我们有输入字段。

当这样的输入字段被聚焦时,我需要它的绝对位置。

是否有办法使用IE> ; 6?


谢谢...


再见斯蒂芬......

Hi,

how can I get the absolute position of a relative element?

We dynamically create a page with multiple segments which are relatively
ordered among each other. In these segments we have input fields.
When such an input field is focused I need it''s absolute position.
Is there a way to do so with IE > 6?

thanks...

bye Stephan...

推荐答案

2004年6月14日星期一17:20:57 +0200,Stephan Koser写道:

....
On Mon, 14 Jun 2004 17:20:57 +0200, Stephan Koser wrote:
....
有办法吗?所以用IE> 6?
Is there a way to do so with IE > 6?




那将是IE 7,IE 8,..会吗? ;-)


-

Andrew Thompson
http://www.PhySci.org/ 开源软件套件
http://www.PhySci.org/codes/ Web& IT帮助
http://www.1point1C.org/ Science&技术



That would be IE 7, IE 8,.. would it? ;-)

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology




" Andrew Thompson" <硒******** @ www.invalid> schrieb im Newsbeitrag

新闻:1r ***************************** @ 40tude.net ...

"Andrew Thompson" <Se********@www.invalid> schrieb im Newsbeitrag
news:1r*****************************@40tude.net...
2004年6月14日星期一17:20:57 +0200,Stephan Koser写道:
...
On Mon, 14 Jun 2004 17:20:57 +0200, Stephan Koser wrote:
...
有没有办法用IE浏览器> 6?
Is there a way to do so with IE > 6?


那将是IE 7,IE 8,..会吗? ; - )



That would be IE 7, IE 8,.. would it? ;-)




哦,对不起 - 那是完全错误的。我的意思是:IE> = 5!


再见...



Oh, sorry - that''s completely wrong. I mean: IE >= 5 !

bye...


2004年6月14日星期一17:20: 57 +0200,Stephan Koser< sk **** @ web.de>写道:
On Mon, 14 Jun 2004 17:20:57 +0200, Stephan Koser <sk****@web.de> wrote:


如何获得相对元素的绝对位置?

我们动态创建一个页面多个彼此相对排序的段。在这些段中,我们有输入字段。
当这样的输入字段被聚焦时,我需要它的绝对位置。
有没有办法用IE> 6?

谢谢...

再见Stephan ......
Hi,

how can I get the absolute position of a relative element?

We dynamically create a page with multiple segments which are relatively
ordered among each other. In these segments we have input fields.
When such an input field is focused I need it''s absolute position.
Is there a way to do so with IE > 6?

thanks...

bye Stephan...




嗨Stephan,


这是来自X库( http://跨浏览器的.com /)。你不必使用图书馆,但这应该给你一些想法。这里没有提供两个库函数:如果所有的参数都是''defined'',则xDef()返回true; xGetElementById()按预期工作。


函数xPageX(e){

if(!(e = xGetElementById(e)))返回0;

var x = 0;

而(e){

if(xDef(e.offsetLeft))x + = e.offsetLeft;

e = xDef(e.offsetParent)? e.offsetParent:null;

}

返回x;

}

函数xPageY(e){

if(!(e = xGetElementById(e)))返回0;

var y = 0;

而(e){

if(xDef(e.offsetTop))y + = e.offsetTop;

e = xDef(e.offsetParent)? e.offsetParent:null;

}

返回y;

}



Hi Stephan,

This is from the X Library (http://cross-browser.com/). You don''t have to use the library, but this should give you some ideas. Two library functions are not provided here: xDef() returns true if all it''s arguments are ''defined''; xGetElementById() works as you would expect.

function xPageX(e) {
if (!(e=xGetElementById(e))) return 0;
var x = 0;
while (e) {
if (xDef(e.offsetLeft)) x += e.offsetLeft;
e = xDef(e.offsetParent) ? e.offsetParent : null;
}
return x;
}
function xPageY(e) {
if (!(e=xGetElementById(e))) return 0;
var y = 0;
while (e) {
if (xDef(e.offsetTop)) y += e.offsetTop;
e = xDef(e.offsetParent) ? e.offsetParent : null;
}
return y;
}


这篇关于相对元素的绝对位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆