vue.js - 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,0,0.9);
}
</style>
解决方案
这里把position:absolute
事情搞砸了......删除了这条线,现在它就像一个魅力!
推荐阅读
- three.js - Three.js 是否支持更复杂的材质
- mysql - Mysql随机记录使用join
- javascript - 使用 Code Runner 在 VSCode 中运行 .js 函数并获取 ReferenceError:
没有定义 - python - 在 Tensorflow 2 中训练时改变 BatchNormalization 动量
- firebase - 条码阅读器扫描条码时如何从 Firestore 中检索数据
- firebase - 部署flutter web应用程序时firebase托管错误409
- ubuntu - ubuntu 20.04:突然“p”键和向上/向下键不起作用
- regex - 用于捕获单引号内的数据的良好正则表达式,但前提是它以某些东西为前缀?
- visual-studio-code - “package.hugo.json”的VSCode文件关联?
- excel - 循环以新名称(日期)多次复制工作表