D
D
Darkness2019-05-21 11:11:15
Vue.js
Darkness, 2019-05-21 11:11:15

How can I smoothly change images in Vue.Js?

Guys, hello, how can I smoothly change pictures in vue?
I attached the element via ref, after the mousover and mouseout events I change the pictures (icons), but how can I achieve smoothness?

a(href="#" class="_available-a" @mouseover="changeIcon" @mouseout="changeIconBack")
    img(src="~assets/img/chrome_icon-white(png).png", 
    alt="chrome icon" 
    ref='icon' 
    width='25')
    span Chrome

changeIconLogo(){
  this.$refs.logoSite.src = require("~/assets/img/logoNotEmpty.png")},
 changeIconBackLogo(){
  this.$refs.logoSite.src = require("~/assets/img/logo_empty.png")}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-05-21
@AntonBrock

transition :

data: () => ({
  image: 0,
  images: [ 'раз картинка', 'два картинка', 'три картинка' ],
}),

<button v-for="(n, i) in images" @click="image = i">
  Показать картинку #{{ i }}
</button>

<transition name="image" mode="out-in">
  <img :key="image" :src="images[image]">
</transition>

.image-enter-active,
.image-leave-active {
  transition: opacity .3s;
}

.image-enter,
.image-leave-to {
  opacity: 0;
}

https://jsfiddle.net/po6ge103/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question