[英]How to get position() per parent of all child
Hi I need to get position of all element that have attribute "data-branch" per parent - .components 嗨,我需要获取每个父元素都具有“数据分支”属性的所有元素的位置-.components
<div class="component">
<ul class="component--list">
<li data-branch="1"><p>item<p></li>
<li><p>item<p></li>
<li>
<p>item<p>
<ul class="component--list">
<li><p>item<p></li>
<li data-branch="2"><p>item<p></li>
</ul>
</li>
<li><p>item<p></li>
<li><p>item<p></li>
</ul>
</div>
I can't use offset() because I have another elements on page with changing hight like expander etc. I must get position only per .components 我无法使用offset(),因为页面上还有其他元素发生了变化,例如expander等。我必须仅按.components获得位置
$('[data-branch="'+ branch.attribute +'"]').each(function(){
var position = $(this).position();
console.log("Top: " + position.top + " Left: " + position.left);
});
Result: 结果:
Top: 594.515625 Left: 90
Top: 155.625 Left: 90
Top: 155.625 Left: 90 because position() get position relative to .component--list not to .component :/ 上:155.625左:90,因为position()获得相对于.component的位置-列表不指向.component:/
What about jQuery UI position ? jQuery UI位置如何?
$('[data-branch="2"]').position({of: '.component'})
in resut jquery ui change position data-branch="2" an change position relative to .component :/ but i need to get coords.. How to use position UI to get top and left? 在result jquery ui更改位置data-branch =“ 2”相对于.component的更改位置:/但我需要获取坐标。.如何使用位置UI来获取顶部和左侧?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.