Approach 1: Implementing Vue Transitions
If you're looking to incorporate a v-if statement, consider utilizing Vue transitions.
Here is an example:
Template
<Transition name="slide">
<div v-if="display">New element<div>
</Transition>
<div>New element<div>
<button @click="display = true">
Display new element
</button>
Style
.slide-enter-active,
.slide-leave-active {
transition: 0.5s ease;
}
.slide-enter-to, .slide-leave {
max-height: 1.5em; // based on your element height
overflow: hidden;
}
.slide-enter, .slide-leave-to {
overflow: hidden;
max-height: 0;
}
(If you prefer not using the overflow hidden effect, consider exploring transforms and opacity for the desired outcome).
For more information on Vue transitions, visit:
https://vuejs.org/guide/built-ins/transition.html
Approach 2: Using CSS Only
Alternatively, achieving this effect can be done solely through CSS by applying the class .display_slide-down
.
Rather than relying on v-if and <transition>
, toggle a class using
:class="display ? 'visible-slide' : ''"
<div class="newelement" :class="display ? 'visible-slide':''">New element</div>
.newelement{
visibility: hidden;
overflow: hidden;
max-height: 0;
}
.newelement.visible-slide{
visibility: visible;
max-height: 1.5em;
}