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.
Thanks in advance!
Maybe my image will it explain better than my horrible english :)

You can try offset method:
var $items = $('.item');
var fh = $items.eq(0).height();
var sh = $items.eq(1).height();
var first = $items.eq(0).offset().top + fh;
var two = $items.eq(1).offset().top;
var distance = (two - first) + (fh/2) + (sh/2) ;
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With