Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
91
rated 0 times [  94] [ 3]  / answers: 1 / hits: 21459  / 8 Years ago, tue, january 3, 2017, 12:00:00

I can't achieve a fade-in fade-out with an image displayed in v-for with VueJS. I want to display image by image using next/prev button.



I read this in documentation :




Vue provides a transition wrapper component, allowing you to add entering/leaving transitions for any element or component in the following contexts:




  • Conditional rendering (using v-if)


  • Conditional display (using v-show)


  • Dynamic components


  • Component root nodes





So I arrange my code to have a v-if in my v-for.



Here a piece of code :



<transition name=fade>
<img id='pvw' v-for='day in days' :src='day.preview' v-if='day.current' title='Preview' />
</transition>


And a little bit of css :



.fade-enter-active, .fade-leave-active {
transition: opacity .5s
}
.fade-enter, .fade-leave-active {
opacity: 0
}


Here is fiddle to see what I am trying to do.



Please help me to achieve this, not sure why it doesn't work.


More From » vue.js

 Answers
26

You have to use TRANSITION GROUP, not TRANSITION.



I would suggest to use something like: https://github.com/asika32764/vue2-animate
which is great package which allows you to use CSS animations from AnimateCSS in your Vue application.



For example, in your case you would use something like that:



<transition-group name=fadeLeft tag=div >
<img v-for=day in days :src='day.preview' v-bind:key=day v-if='day.current' title='Preview'>
</transition-group>

[#59479] Saturday, December 31, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
khalilb

Total Points: 173
Total Questions: 110
Total Answers: 105

Location: Honduras
Member since Thu, Mar 23, 2023
1 Year ago
;