简体   繁体   English

vuejs中图片之间的转换

[英]Transition between images in vuejs

I want to create a smooth transition between 2 images with a legend.我想在两个带有图例的图像之间创建一个平滑的过渡。 The images come from an object-array of images.图像来自图像对象数组。

Because works only on single tags and components, I've created a component to define the image+legend.因为仅适用于单个标签和组件,所以我创建了一个组件来定义图像+图例。

<transition>
    <home-image :slide="slide" :key="slide"></home-image>
</transition>

The classes I define are like this我定义的类是这样的

.v-enter-active,
.v-leave-active {
    transition: opacity 2s ease-in-out;
}

.v-leave,
.v-enter-to {
    opacity: 1;
}

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

The new image is returned by a method新图像由方法返回

updateSlide() {
    this.slide = this.entries[ Math.floor( Math.random() * this.entries.length ) ];
}

where entries is my array defined in data其中条目是我在数据中定义的数组

this.slide is updated in regular intervals, every 10seconds like this, which is defined in the created() section this.slide 定期更新,像这样每 10 秒更新一次,这在 created() 部分中定义

this.updateSlide();
this.uSlide = setInterval( this.updateSlide, 10000);

The code works, in the sense that a new image is loaded in this.slide every 10 seconds.该代码有效,因为每 10 秒在 this.slide 中加载一个新图像。 However, the transitions work only "half-way".但是,转换仅“半途而废”。

There is no transition fading out: the "old image" disappears and makes way for the new image fading in.没有过渡淡出:“旧图像”消失并为新图像淡入让路。

However, what I'd like is a smooth transition from one to the other.但是,我想要的是从一个到另一个的平稳过渡。

I've tried more than a couple of ideas including using mode="out-in" and "in-out" but nothing works as I want.我已经尝试了不止几个想法,包括使用 mode="out-in" 和 "in-out",但没有什么能如我所愿。

What am I overlooking?我在看什么?

Found out position in v-enter and v-leave had to be set.发现必须设置 v-enter 和 v-leave 中的 position。

Code is now:代码现在是:

.v-leave,
.v-enter-to {
    position: relative;
    opacity: 1;
}

.v-enter,
.v-leave-to {
    position: absolute;
    opacity: 0;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM