[英]How can I find the position in the page of an element using jQuery?
I'm aware of the position method, but that retrieves the position relative to the offset parent. 我知道位置方法,但它检索相对于偏移父项的位置。 Do I just throw in a loop to transverse up the document nodes? 我只是投入一个循环来横向文档节点?
I guess that I'm surprised that it isn't part of the core, and I'm wondering if it's tucked away somewhere that I don't know about. 我想我很惊讶它不是核心的一部分,我想知道它是否隐藏在某些我不知道的地方。
jQuery(elem).offset();
Without jQuery you can use: 没有jQuery你可以使用:
document.getElementById('elemId').clientTop
document.getElementById('elemId').clientLeft
or 要么
document.getElementById('elemId').offsetTop
document.getElementById('elemId').offsetLeft
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.