I have a div
at the top of my page, containing some header text, which, upon mouseenter
, should expand (in height), to reveal some smaller text. Then, upon mouseleave
, it should then retract. This is harder than it sounds...
The solution must:
- Go from a height to fit just the header, to a height to fit all the text.
- Transition from one to the other.
- Try to use pure CSS.
- Have the expanding animation pause if the mouse leaves, and visa versa (default in CSS, but not in jQuery).
I have tried:
- Using
:hover
in my stylesheet, to change from a set pixel value, toauto
, as seen in this question (but in mine it is pure CSS). This did not transition. - Using a set height upon expansion, which does not work on different viewport sizes.
- Using
max-height
, and expanding it to something larger than the actual expandeddiv
would get, as seen in this question. This meant that the transitions don't work properly, and look different on different devices. - Using
jQuery
.animate()
, using the pixel value of auto, to then create a transition, as seen in this question, but the animation has to finish before starting the next one, meaning that a series of animations could continue for a long time after the user's mouse if far away from thediv
.
See all four above examples here.
As said, pure CSS would be ideal, but if not possible, I would be fine with JavaScript (and I prefer jQuery).
Thanks! :)