Whats the problem?
The $y Variable at the end of your loop contains the total height if you add the height of one element, which is in your case 68pixel (4.6875em)
Just print it out e.g. into a javascript variable.
echo '<script type="text/javascript">totalHeight = '.($y+68).';</script>';