如何获得2个元素之间的距离(中间点)? [英] How can I get the distance between 2 elements (middle point)?
本文介绍了如何获得2个元素之间的距离(中间点)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要你的帮助!我在它们之间放置了随机数量的div。
i need your help! I have a random amount of divs placed between themselves.
<div id="items">
<div class="item">Item description</div>
<div class="item">Item description</div>
<div class="item">Item description</div>
<div class="item">Item description</div>
</div>
每个都有不同的高度,我必须计算它们之间的距离。距离每个项目的每个中间点非常重要。
Each of the has a different height and i have to calculate the distance between them. It is really important that the distance is from each middle point of each item.
提前致谢!
也许我的形象会比我糟糕的英语更好地解释:)
Maybe my image will it explain better than my horrible english :)
推荐答案
哦,天哪!有时它比你想象的要容易!
Oh my gosh! Sometimes it is easier than you might think!
var currentCenterPoint = $('.current').outerHeight() / 2;
var nextCenterPoint = $('.current').next().outerHeight() / 2;
var amount = (currentCenterPoint + nextCenterPoint);
这篇关于如何获得2个元素之间的距离(中间点)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文