example
It has the same effect as this animation. p is hidden first. After clicking the button, it is displayed and has animation effect. It is the same when it is hidden. But I definitely wrote it too complicatedly. Is there a simpler solution (without third-party libraries)?
Try using transition:
demo
The simpler idea is:
The block does not need to be hidden, just set the height to 0 and it will be invisible
Use
transition
to achieve animation effectsThere is no need to use the two class names
hidden
andshow
to control it. In fact, it only has two states, so it can be considered that withoutshow
it is hiddenIn addition, there is no need to write a
show()
andhide()
to bind them separately. In fact, you can click this button to expand it, click it again to hide it, and use atoggle()
to switch the display stateI made some modifications to your code, as follows:
https://jsfiddle.net/boxsnake...
The question can be solved with CSS3 (if it does not need to be compatible with IE)
Can it be implemented with jquery?