[英]how to get top and left properties of offsetParent div?
As we can get offset top of an element by using like this: 因为我们可以通过使用这样的方式获得元素的顶部偏移:
$(selector).offset().top;
But how can we get the top value of parent offset div? 但是我们怎样才能获得父偏移div的最高值?
I've tried like this but doesn't work? 我试过这样但不起作用?
$(selector).offsetParent().top;
Try to use parent() like, 尝试使用parent()之类的,
$(selector).parent().offset().top;
Read Get position/offset of element relative to a parent container? 读取元素相对于父容器的位置/偏移量?
Um, you can use like this: 嗯,你可以像这样使用:
$(selector).offsetParent().offset().top;
see documentation on offsetParent 请参阅有关offsetParent的文档
offsetParent doesn't get offset value but it just select the closest positioned parent div. offsetParent没有得到偏移值,但它只是选择最接近定位的父DIV。 You can get the offset/position by using offset and position . 您可以使用偏移和位置来获得偏移/ 位置 。
Don't forget you have to go get offsets all the way to the topmost parent. 不要忘记你必须一直到最顶层的父母。 If you have enough nested content it's probably worth writing a recursive function to get after it. 如果你有足够的嵌套内容,那么编写一个递归函数来获取它可能是值得的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.