vue实现淡入淡出

直接看代码

<template>
    <div class="pic">
        <ul class="tu">
            <transition-group name="img">
            <li v-for="(item,index) in pic" :key="index" v-show="index===mark" @mouseenter="stop" @mouseleave="go">
                <img :src="item" :key="index">
            </li>
            </transition-group>
        </ul>
        <ul class="bannerBtn">
            <li v-for="num in 3">
                <a href="javascript:;" :style="{background:num-1===mark?'#ff7800':''}" @click='change(num-1)' class='aBtn'></a>
            </li>
        </ul>
    </div>
</template>

<script>
    export default {

        data(){
            return{
                pic:["../../../static/image/1.png","../../../static/image/2.png",
                    "../../../static/image/3.png"],
                mark:0,
                timer:''
            }
        },
        created() {
            this.play()
        },
        methods:{
            autoplay(){
                if(this.mark<this.pic.length-1){
                    this.mark++;
                }else{
                    this.mark = 0;
                }

            },
            play(){
                this.timer=setInterval(this.autoplay,5000)
            },
            change(num){
            this.mark=num;
            },
            stop(){
                clearInterval(this.timer);
                this.timer=null;
            },
            go(){
                this.timer=setInterval(this.autoplay,5000)
            }
        }
    }
</script>

<style scoped>
.pic{
    position: relative;
    margin-left:100px;
    margin-top:40px;
    width:550px;
    height:305px;
}
img{width:100%;
    height:100%;
}
.tu li{position:absolute;
        top:0;
        left:0;
        list-style: none;
    }
.img-enter-active,
.img-leave-active {
    transition: all 4s;
}

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

.img-enter-to,
.img-leave {
    opacity: 1;
}
.aBtn{transition:all 4s ease;}
.bannerBtn li{
    float:left;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    list-style:none;
}
.bannerBtn li a{
    margin-left:2.5px;
    margin-top:1.5px;
    display: block;
    width: 10px;
    height: 10px;
    border:0.5px solid white;
    border-radius: 50%;
}
.bannerBtn{
    width: 70px;
    position:absolute;
    left:35%;
    top:250px;
    bottom:22px;
    height:20px;
    text-align: center;
}
</style>

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值