Cannottypecode 2023-12-01 17:32 采纳率: 0%
浏览 2

但是图片切换的时候切换的淡出淡入效果不出现各位能不能帮我看看什么情况,控制台也不报错(相关搜索:轮播图)

这是我写的一个轮播图组件,用vite创建的vue项目,但是图片切换的时候切换的淡出淡入效果不出现各位能不能帮我看看什么情况,控制台也不报错


<template>
    <div class="">
        <div id="box">
            <div class="banner">
                <!--切换的图片-->
                <div class="bannerImg">
                    <transition-group name="fade" tag="ul"  >
                        <li v-for="(item, index) in slideList" :key="index">
                            <a>
                                <img @mouseenter="changeInterval(true)" @mouseleave="changeInterval(false)"
                                    :src="item.image" v-show="index == currentIndex" />
                            </a>
                        </li>
                    </transition-group>
                </div>
                <!--切换的小按钮-->
                <div class="bannerItems">
                    <span v-for="(item, index) in slideList" :class="index == currentIndex ? 'active' : ''"
                        @click="changeImg(index)">{{ index + 1 }}</span>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    name: "",
    data() {
        return {
            slideList: [
                { 'clickURL': '#', 'desc': '美食1', 'image': '/img/1.jpeg' },
                { 'clickURL': '#', 'desc': '美食2', 'image': '/img/2.webp' },
                { 'clickURL': '#', 'desc': '美食3', 'image': '/img/3.webp' },
                { 'clickURL': '#', 'desc': '美食4', 'image': '/img/4.webp' },
                { 'clickURL': '#', 'desc': '美食5', 'image': '/img/5.webp' },
                { 'clickURL': '#', 'desc': '美食6', 'image': '/img/6.webp' },
            ],
            currentIndex: 0,
            timer: null
        }
    },
    components: {
    },
    methods: {
        //定时器
        startInterval() {
            // 事件里定时器应该先清除在设置,防止多次点击直接生成多个定时器
            clearInterval(this.timer);
            this.timer = setInterval(() => {
                this.currentIndex++;
                if (this.currentIndex > this.slideList.length - 1) {
                    this.currentIndex = 0
                }
            }, 3000)
        },
        //园点切换图片
        changeImg(index) {
            this.currentIndex = index
        },
        //鼠标移入移出
        changeInterval(val) {
            if (val) {
                clearInterval(this.timer)
            } else {
                this.startInterval()
            }
        },
    },
    mounted() {
        this.startInterval()
    }
}
</script>

<style scoped>


* {
    margin: 0;
    padding: 0;
}

ul li {
    list-style: none;
}

a {
    text-decoration: none;
}

.banner {
    width: 1080px;
    height: 720px;
    margin: 20px auto;
    position: relative;
}

.bannerImg img {
    width: 1080px;
    height: 720px;
    position: absolute;
    z-index: 800;
}

.bannerItems {
    position: absolute;
    z-index: 1000;
    bottom: 0;
    width: 100%;
    padding: 10px 0;
    display: flex;
    flex-direction: row;
    justify-content: center;
}


.bannerItems span {
    width: 30px;
    height: 30px;
    background: rgba(100, 100, 100, .6);
    margin: 0 5px;
    border-radius: 50%;
    font-size: 16px;
    font-weight: bold;
    font-family: Microsoft YaHei;
    line-height: 30px;
    text-align: center;
    color: white;
    cursor: pointer;


}

.bannerItems span.active {
    background-color: red;
}

/* 过渡效果样式-实现图片的淡入淡出效果 */
.fade-leave-active,
.fade-enter-active {
    transition: opacity 0.5s ease;
}

.fade-leave-from,
.fade-enter-to {
    opacity: 0;
}
</style>


  • 写回答

2条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2023-12-01 20:54
    关注

    【相关推荐】




    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^
    评论

报告相同问题?

问题事件

  • 创建了问题 12月1日

悬赏问题

  • ¥15 人脐静脉内皮细胞(HEUVC)重悬后自动聚团,怎么解决?
  • ¥30 faiss 的 IndexFlatL2 相似性搜索
  • ¥20 找人开发一套大数据算法系统!
  • ¥15 pycharm中cv2安装后可以用但是无法补全或跳转函数,搜索后使用以下方法无效1.重新安装包(更换版本也不行,如何解决?
  • ¥15 如何关闭Win11文件资源管理器的搜索栏的预选词
  • ¥15 odoo17非生产订单产品出库整个业务流程处理
  • ¥20 寻大数据算法的技术!
  • ¥15 悬赏 关于#c++#的问题
  • ¥15 python 处理文本报错问题
  • ¥15 k8s安装calico失败,pod状态为Init:ImagePullBackOff