所以我有一个喜欢的div:
<div class="uiGrid">
<div class="trigger"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
我想知道触发器对uiGrid的位置并试过这两个:
$('.trigger').offset('.uiGrid');
$('.trigger').position('.uiGrid');
Run Code Online (Sandbox Code Playgroud)
但都没有得到它.偏移量相对于文档而言,位置相对于父级而不是指定的元素.
我该怎么做?谢谢
Ya *_*ang 86
只做减法你的自我...
var relativeY = $("elementA").offset().top - $("elementB").offset().top;
Pra*_*ake 11
你可以在这里做的基本上是从子属性值中减去父属性值.
var x = $('child-div').offset().top - $('parent-div').offset().top;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
66350 次 |
| 最近记录: |