javascript - CSS 绝对和相对不适用于我的 div 滑块轮播
问题描述
我正在尝试使用 VUE 制作滑块轮播,css 类(3 个 div)在 for 循环中运行。每当一个 div 淡出时,下一个滑块会在底部创建一个双滑块,这意味着两个滑块同时运行。
每当我使用相对和绝对属性时,我的 div 就会完全消失。我不知道该怎么办
<template>
<h1 class="text-center">SLIDER APP</h1>
<div>
<div v-for="(color, index) in slider" :key="color">
<transition name="fade">
<div v-if="currentslide == index" :class="color"></div>
</transition>
</div>
</div>
</template>
<script>
export default {
data(){
return {
currentslide:0,
intervals:'',
slider:['first-slider', 'second-slider', 'third-slider'],
isshowing:true,
}
},
mounted(){
this.intervals = setInterval(() => {
console.log('This is slide', this.currentslide)
this.currentslide = this.currentslide == 2 ? 0:this.currentslide+1;
}, 2000);
},
beforeUnmount(){
clearInterval(this.intervals)
}
}
</script>
<style>
.first-slider {
background: blue;
height: 350px;
}
.second-slider {
background: red;
height: 350px;
}
.third-slider {
background: orange;
height: 350px;
}
.fade-enter-active, .fade-leave-active {
transition: all 0.5s ease;
}
.fade-enter-from, .fade-leave-to {
opacity: 0;
transform: translateX(30px);
}
</style>
解决方案
停止使用绝对或相对定位。而是在外部 div 上使用 display flex 以获得良好的定位结果。
推荐阅读
- tfs - 从 Team Foundation 服务帐户组中删除非活动用户
- r - 在 R 的 1 个绘图区域中放置 4 个直方图
- typescript - 如何为 Angular 8 中的选项卡编写点击事件
- ionic-framework - 按类别过滤产品
- asp.net - 如何对在 localhost 上运行的 .NET 项目的 API 调用失败进行故障排除?
- mysql - 将 GROUP BY 与 MAX()/MIN() 一起使用会产生不好的结果
- google-apps-script - Google 驱动器权限 api 仅在 20 次调用后引发速率限制错误
- python - 使用请求将变量插入 Python 中的 SQL 查询
- java - Java正则表达式和“贪婪”或早期搜索斜线
- java - 设置 this.updateTime 但它在运行测试时抛出 NullPointerException