Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
364 views
in Technique[技术] by (71.8m points)

javascript - 如何使用jQuery找到元素的绝对位置?(How do I find the absolute position of an element using jQuery?)

有没有办法使用jQuery找到元素的绝对位置,即相对于窗口的开始?

  ask by akshat translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

.offset() will return the offset position of an element as a simple object, eg:

(.offset()将元素的偏移位置作为简单对象返回,例如:)

var position = $(element).offset(); // position = { left: 42, top: 567 }

You can use this return value to position other elements at the same spot:

(您可以使用此返回值将其他元素定位在同一位置:)

$(anotherElement).css(position)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...