vue element 走马灯(el-carousel)鼠标控制翻页

21 篇文章 1 订阅

项目上需要一个轮播图的,之前用js和jq写过,最近,我想用element的走马灯效果改成轮播图的效果,我就百一下,发现还真有这个功能,然后我就借鉴一下,然后就有此文章了,文章最后有转载地址。

<template>
    <div @wheel="goWheel">
        <div class="block">
            <el-carousel 
                height="100vh" 
                direction="horizontal" 
                :autoplay="true"              
                trigger="click" 
                ref="swiper" 
                :loop="true"
            >
                <el-carousel-item v-for="item in 4" :key="item" >
                    <h3 class="small">{{ item }}</h3>
                </el-carousel-item>
            </el-carousel>
        </div>
    </div>
</template>
<script> 
    export default {
        data(){
            return {
                one:true,//以此来控制每次轮播图切换的张数
            }
        },
        created(){
  
        },
        mounted(){
        },
        methods: {
            goWheel() {
                if (event.deltaY > 0 && this.one==true) { 
                    this.$refs.swiper.next();   
                    this.one=false;
                    setTimeout(()=>{
                        this.one=true
                    },1000)
                }
                
                if (event.deltaY < 0 && this.one==true) {
                    this.$refs.swiper.prev();
                    this.one=false;
                    setTimeout(()=>{
                        this.one=true
                    },1000)
                }
            },
        },
    }
</script>
<style>
    .el-carousel__item h3 {
        color: #475669;
        font-size: 14px;
        opacity: 0.75;
        line-height: 150px;
        margin: 0;
    }

    .el-carousel__item:nth-child(2n) {
        background-color: #99a9bf;
    }
    
    .el-carousel__item:nth-child(2n+1) {
        background-color: #d3dce6;
    }
</style>
<style type="text/css">
</style>
  

@wheel 是vue鼠标滚动事件。

转载:https://blog.csdn.net/Mayisheart/article/details/122384551?spm=1001.2014.3001.5502

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值