Let’s combine three things we just learned here on CSS-Tricks:
One, transitioning to auto dimensions. Two, Ajaxing for stuff in a modern way. Three, waiting for images to be loaded to measure them.
With all these three things in our toolbox, we can Ajax for some arbitrary content and insert it onto the page with a revealing height animation. Tricky tricky!
Here’s the final demo:
See the Pen Slide in Ajax Content by Chris Coyier (@chriscoyier) on CodePen.
In the grand tradition of “writing a script”, here’s ours:
- Ajax for the stuff
- Make a dummy element that is exactly as wide as where you plan to inject the stuff
- Inject your stuff into the dummy element
- Measure dummy element (carefully)
- Inject your stuff into the real (and collapsed) element
- Transition the height to the measured height
- Clean up after yourself
All the code is commented line-by-line in the demo.
Animate in Ajax’d Content to its Natural Height is a post from CSS-Tricks