I have this scss code in my vue app. I’m trying to make a smooth transition from left for a menu when the isVisible
property is set to true but I’m not able to apply the transition I’ve defined and the menu will instantly appear.
I’ve done a reserach here on SO and I’ve found some interesting questions but all of them are using jQuery and css animation
so they are not really useful.
I’m not a CSS master, any suggestion about?
HTML
JavaScript
x
4
1
<div class="col-12 settings p-3 position-fixed" :class="{ 'show': isVisible }" ref="settings" v-if="isVisible">
2
<h4>Settings</h4>
3
</div>
4
CSS
JavaScript
1
13
13
1
.settings {
2
top: 0;
3
width: 50%;
4
height: 100vh;
5
background-color: white;
6
transform: translateX(-100%);
7
transition: transform 0.5s ease;
8
&.show {
9
transform: translateX(0);
10
transition: transform 0.5s ease;
11
}
12
}
13
Advertisement
Answer
This is done with <transition>
Here an example:
JavaScript
1
6
1
<transition name="slide">
2
<div class="col-12 settings p-3 position-fixed" class="settings" v-if="isVisible">
3
<h4>Settings</h4>
4
</div>
5
</transition>
6
CSS class
JavaScript
1
13
13
1
.slide-enter-active, .slide-leave-active {
2
transition: transform .5s;
3
}
4
.slide-enter, .slide-leave-to {
5
transform: translateX(-200px);
6
}
7
.settings {
8
top: 0;
9
width: 50%;
10
height: 100vh;
11
background-color: white;
12
}
13
Its really not that hard
Take a look: https://v2.vuejs.org/v2/guide/transitions.html