I'm struggling with vue transitions trying to show / hide content using v-if smoothly. Whilst I understand the css classes and transitions, I can make the content appear 'smoothly' using things like opacity or translation etc...but once the animation is complete (or rather as it starts), any html sections below seem to 'jump'.
I'm trying to achieve the same affect as the Bootstrap 4 'collapse' class - click one of the top buttons here: https://getbootstrap.com/docs/4.0/components/collapse/
As the hidden section appears / disappears, all the html content 'slides' nicely with it.
Is this possible using Vue transition for content being shown using v-if? All the samples on the vue transitions docs, whilst having great css transition effects, have the below html 'jump' once the transition has started or is complete.
I've seen some pure js solutions using max-height - https://jsfiddle.net/wideboy32/7ap15qq0/134/
and tried with vue: https://jsfiddle.net/wideboy32/eywraw8t/303737/
.smooth-enter-active, .smooth-leave-active {
transition: max-height .5s;
}
.smooth-enter, .smooth-leave-to {
max-height: 0 .5s;
}
Thanks!
If you want to animate max-height, then you should enter the amount of max-height for the element you want to animate, also correct the second class as you put 's' (or seconds) in max-height definition :
p{
max-height: 20px;
}
.smooth-enter-active, .smooth-leave-active {
transition: max-height .5s;
}
.smooth-enter, .smooth-leave-to {
max-height: 0;
}
if you want something like bs4 collapse then the example inside vue website will do :
.smooth-enter-active, .smooth-leave-active {
transition: opacity .5s;
}
.smooth-enter, .smooth-leave-to {
opacity: 0
}
Edit :
What you are trying to do is achievable by first finding out the height of the content and then setting it inside .*-enter-to
and .*-leave
classes. One way to do that is demonstrated in fiddle below :
https://jsfiddle.net/rezaxdi/sxgyj1f4/3/
You can also completely forget about v-if or v-show and just hide the element using height value which I think is a lot smoother :