如何解决VueJS 过渡组不适用于图像,如何淡化图像?
我正在尝试创建一个图像滑块,它可以淡化图像。图像 1 应该在图像 2 淡入的同时淡出。换句话说:它们之间不应该有间隙。现在它不像褪色那样做。该代码正在工作,到目前为止,当用户单击“下一步”时,当前图像消失,0.9 秒后出现下一张图像。它们之间有 0.9 秒的延迟(与 CSS 中声明的数量相同),因此它以某种方式识别过渡时间。它只是不褪色,单击按钮后它立即消失。我错过了什么?
我的代码
<template>
<div>
<transition-group name='fade' tag='div'>
<div v-for="i in [currentIndex]" :key='i'>
<img :src="currentImg" />
</div>
</transition-group>
<a class="prev" @click="prev" href='#'>❮</a>
<a class="next" @click="next" href='#'>❯</a>
</div>
</template>
<script>
export default {
data() {
return {
images: [
'https://cdn.pixabay.com/photo/2015/12/12/15/24/amsterdam-1089646_1280.jpg','https://cdn.pixabay.com/photo/2016/02/17/23/03/usa-1206240_1280.jpg','https://cdn.pixabay.com/photo/2015/05/15/14/27/eiffel-tower-768501_1280.jpg','https://cdn.pixabay.com/photo/2016/12/04/19/30/berlin-cathedral-1882397_1280.jpg'
],timer: null,currentIndex: 0,show: true
};
},mounted: function () {
this.startSlide();
},methods: {
startSlide: function () {
this.timer = setInterval(this.next,4000);
},next: function () {
this.currentIndex += 1;
},prev: function () {
this.currentIndex -= 1;
},},computed: {
currentImg: function () {
return this.images[Math.abs(this.currentIndex) % this.images.length];
},};
</script>
<style>
.fade-enter-active,.fade-leave-active {
transition: all 0.9s ease;
overflow: hidden;
visibility: visible;
position: absolute;
width:100%;
opacity: 1;
}
.fade-enter,.fade-leave-to {
visibility: hidden;
width:100%;
opacity: 0;
}
img {
height:600px;
width:100%
}
.prev,.next {
cursor: pointer;
position: absolute;
top: 40%;
width: auto;
padding: 16px;
color: white;
font-weight: bold;
font-size: 18px;
transition: 0.7s ease;
border-radius: 0 4px 4px 0;
text-decoration: none;
user-select: none;
}
.next {
right: 0;
}
.prev {
left: 0;
}
.prev:hover,.next:hover {
background-color: rgba(0,0.9);
}
</style>
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。