ElementUI Carousel 取消hover暂停轮播的默认行为

Carousel 在根节点上绑定了 mouseenter 和 mouseleave:

复制代码
// carousel 源码中的模板`
`on:` `{`
  `mouseenter:` `function($event)` `{`
      `_vm.handleMouseEnter($event)`              
  `},`
  `mouseleave:` `function($event)` `{`
      `_vm.handleMouseLeave($event)` 
  `}`
`}`
`

默认handleMouseEnter和handleMouseLeave事件为:鼠标移入的时候会暂停轮播,鼠标移出会恢复轮播。

复制代码
handleMouseEnter()` `{`
  `this.hover =` `true;`   `// 用于控制箭头显示`
  `this.pauseTimer();`   `// 暂停轮播`
`},`
`handleMouseLeave()` `{`
  `this.hover =` `false;`
  `this.startTimer();`   `// 恢复轮播`
`}`
`

取消轮播方式,重写这两个方法:

复制代码
` `<el-carousel ref="bannerCarousel"` `:height="bannerHeight"` `:interval="3000" arrow="hover" indicator-position="none" @change="onBannerChange">`
        `<el-carousel-item v-for="(slide, index) in slides"` `:key="slide.key">`
          `<div class="banner-slide">`
            `<img class="banner-img"` `:src="shouldLoadBanner(index) ? getBannerImgUrl(slide.img) : ''"` `:alt="slide.title"/>`
          `</div>`
        `</el-carousel-item>`
      `</el-carousel>`
`
复制代码
const carousel =` `this.$refs.bannerCarousel`
`carousel.handleMouseEnter` `=` `function` `()` `{` 
    `this.hover =` `true` 
`}`
`carousel.handleMouseLeave` `=` `function` `()` `{` 
    `this.hover =` `false` 
`}`
`
相关推荐
木梓辛铭2 小时前
关于Chrome无法上网的问题2
前端·chrome
品克缤2 小时前
解决 SVG 作为 CSS 背景图无法 background-size: 100% 100% 拉伸的问题
前端·css·vue.js·css3
小彭努力中2 小时前
190.Vue3 + OpenLayers 实战:实现地图旋转移动动画 + CSS缩放动画(详解 animate 用法)
前端·css·openlayers·cesium·webgis
Mintopia2 小时前
从架构起步:如何在软件开发初期决定交付速度与质量
前端·架构
wuhen_n2 小时前
Prompt工程进阶:少样本与思维链
前端·javascript·ai编程
读忆2 小时前
NVM 安装低版本 Node.js 失败解决方案
前端·javascript·node.js
Mintopia2 小时前
AI 改变手敲编程:开发流程被重写的 6 个环节
前端·人工智能
CharlieWang2 小时前
Vite 终于有了一个很轻的服务端搭档
前端·vite·mcp
new code Boy2 小时前
Vue3转React速查表
前端·javascript·react.js