鼠标滚动切换页面

elementui Carousel 走马灯+鼠标滚轮事件实现

一、在轮播图外的盒子添加鼠标滚轮事件触发GoWheel函数

 @wheel="goWheel"

二、通过判断deltaY的数值触发相应事件

检查滚轮事件deltaY属性是否大于0

event.deltaY

鼠标滚轮向下滚动时,其返回值大于零,向上滚动时其返回值小于零。

三、通过ref 获取轮播元素,再通过相应方法控制轮播执行事件,详情见element ui 官网事件

this.$refs.swiper.next();

this.$refs.swiper.prev();

代码

<div @wheel="goWheel"&gt; 
        
    <el-carousel height="100vh" direction="vertical" :autoplay="false" @change="load"             
           trigger="click" ref="swiper" :loop="false"&gt;
 
 
             <el-carousel-item&gt;
 
             </el-carousel-item&gt;
 
    </el-carousel&gt;
 
</div&gt;

el-carousel-item里面放切换的图片视频

goWheel() {
    if (event.deltaY &gt; 0 &amp;&amp; this.one==true) { //data定义one为trueone为true执行
          this.$refs.swiper.next();           //以此来控制每次轮播图切换的张数
          this.one=false;
          setTimeout(()=&gt;{
              this.one=true
          },1000)
    }
    
    if (event.deltaY < 0 &amp;&amp; this.one==true) {
        this.$refs.swiper.prev();
        this.one=false;
        setTimeout(()=>{
            this.one=true
        },1000)
    }
},

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注