title: How does jQuery Slidedown get final height of hidden item before showing it?
body: <p>I'm trying to replicate jQuery <code>slideDown()</code> in GSAP and I'm having trouble working out how jQuery calculates the height of an item which is currently hidden as if it was set to <code>height:auto</code>.</p>
  
  <p>I've tried trawling the code on GitHub but can't find any code which seems to be doing this in <code>jQuery.fn.slideDown</code> or <code>jQuery.fn.animate</code> which it calls.</p>
  
  <p>There are several similar questions on SO and several solutions proposed, all of which seem to have their own problems:</p>
  
  <ol>
  <li><p><strong>Clone the element, position it off screen and calculate its height.</strong><br><br> This won't work if the element or any of its child elements have a height set by CSS styles which require the element to be in its original place in the DOM (e.g. an <code>.accordianItem</code> might only be styled if it's inside its <code>.accordian</code>).</p></li>
  <li><p><strong>Display the item, remove <code>height:0</code> and quickly calculate the height before hiding the element again and then stating the animation.</strong><br><br> This might flash the content quickly while calculating the height.</p></li>
  <li><p><strong>Use <code>visibility:true</code> to show it in place while calculating the height.</strong><br><br> This would stop the flash and still keep the element in the same position in the DOM for correct height calculation, but it would still push other items below it down because <code>visibility:false</code> items still have a height.</p></li>
  <li><p><strong>Calculate the height of an item before it's hidden and store it in a data attribute so we know it when we want to open the item later.</strong><br><br> This won't work if any dynamic content changes the height of the item whilst it's hidden.</p></li>
  </ol>
  
  <p><code>jQuery slideDown()</code> "just works" every time so I'd be really interested to know <em>how</em> it works, but I just can't work out where it's doing this. I'm also surprised that GSAP can't do this out of the box, or that nobody has shared a proper solution to this before.</p>
  
  <p>Any help would really be appreciated.</p>