Lightweight React component for animating height using CSS transitions. Slide up/down the element, and to any specific height. Check the demo below.
CSS classes are applied in specific animation states, check animationStateClasses
prop.
Detailed documentation is available on GitHub.
Import the component, and use it to wrap content whose height you want to animate.
import AnimateHeight from 'react-animate-height'; <AnimateHeight duration={ 500 } height={ 'auto' } > <h1>Your content goes here</h1> <p>Put as many React or HTML components here.</p> </AnimateHeight>
Current Height: 0
Set height to:
For this example, duration is set to 500ms. If you open up the console, you'll see onHeightAnimationEnd
andonHeightAnimationStart
callbacks. Also, animateOpacity
is set to true.
Current Height: auto
Set height to:
It looked serious, but we in California, like everywhere else, were not alarmed. We were sure that the bacteriologists would find a way to overcome this new germ, just as they had overcome other germs in the past. But the trouble was the astonishing quickness with which this germ destroyed human beings, and the fact that it inevitably killed any human body it entered. No one ever recovered. There was the old Asiatic cholera, when you might eat dinner with a well man in the evening, and the next morning, if you got up early enough, you would see him being hauled by your window in the death-cart. But this new plague was quicker than that—much quicker.
From the moment of the first signs of it, a man would be dead in an hour. Some lasted for several hours. Many died within ten or fifteen minutes of the appearance of the first signs.
The heart began to beat faster and the heat of the body to increase. Then came the scarlet rash, spreading like wildfire over the face and body. Most persons never noticed the increase in heat and heart-beat, and the first they knew was when the scarlet rash came out. Usually, they had convulsions at the time of the appearance of the rash. But these convulsions did not last long and were not very severe. If one lived through them, he became perfectly quiet, and only did he feel a numbness swiftly creeping up his body from the feet. The heels became numb first, then the legs, and hips, and when the numbness reached as high as his heart he died. They did not rave or sleep. Their minds always remained cool and calm up to the moment their heart numbed and stopped. And another strange thing was the rapidity of decomposition. No sooner was a person dead than the body seemed to fall to pieces, to fly apart, to melt away even as you looked at it. That was one of the reasons the plague spread so rapidly. All the billions of germs in a corpse were so immediately released.
If you want AnimateHeight
to automatically adapt on content change, you can use ResizeObserver. You can find the code for this example here.
Here you can see delay
prop in action. Parent's div height is set to 500px.
Current Height: auto
Current Delay: 0
Set delay to:
Set height to:
It looked serious, but we in California, like everywhere else, were not alarmed. We were sure that the bacteriologists would find a way to overcome this new germ, just as they had overcome other germs in the past. But the trouble was the astonishing quickness with which this germ destroyed human beings, and the fact that it inevitably killed any human body it entered. No one ever recovered. There was the old Asiatic cholera, when you might eat dinner with a well man in the evening, and the next morning, if you got up early enough, you would see him being hauled by your window in the death-cart. But this new plague was quicker than that—much quicker.
From the moment of the first signs of it, a man would be dead in an hour. Some lasted for several hours. Many died within ten or fifteen minutes of the appearance of the first signs.
The heart began to beat faster and the heat of the body to increase. Then came the scarlet rash, spreading like wildfire over the face and body. Most persons never noticed the increase in heat and heart-beat, and the first they knew was when the scarlet rash came out. Usually, they had convulsions at the time of the appearance of the rash. But these convulsions did not last long and were not very severe. If one lived through them, he became perfectly quiet, and only did he feel a numbness swiftly creeping up his body from the feet. The heels became numb first, then the legs, and hips, and when the numbness reached as high as his heart he died. They did not rave or sleep. Their minds always remained cool and calm up to the moment their heart numbed and stopped. And another strange thing was the rapidity of decomposition. No sooner was a person dead than the body seemed to fall to pieces, to fly apart, to melt away even as you looked at it. That was one of the reasons the plague spread so rapidly. All the billions of germs in a corpse were so immediately released.