swiper 鼠标放上去停止滚动

 

方法:

 @mouseenter.native="enter"
 @mouseleave.native="leave"


computed: {
    swiper() {
      return this.$refs.myBotSwiper.swiper;
    }
  },



 enter() {
      this.swiper.autoplay.stop();
    },

  leave() {
      this.swiper.autoplay.start();
    },




computed: {
    swiper() {
      return this.$refs.myBotSwiper.swiper;
      //大坑在这之前都是this.$refs.myBotSwiper.swiper
      //而4.1.1是this.$refs.myBotSwiper.swiperInstance
    }
  },

注意:

computed: {

    swiper() {

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现鼠标悬浮停止滚动,可以使用 `swiper` 的 `autoplay` 参数和 `noSwiping` 参数。 具体步骤如下: 1. 在 `swiper` 的 `autoplay` 参数中设置一个自动轮播的间隔时间,如 `autoplay: { delay: 5000 }`。 2. 使用 `noSwiping` 参数禁止用户手动滑动轮播,只允许通过自动轮播进行切换,如 `noSwiping: true`。 3. 监听 `swiper` 的 `mouseenter` 和 `mouseleave` 事件,当鼠标悬浮在轮播上时停止自动轮播,当鼠标离开轮播时重新开始自动轮播。 代码示例: ```vue <template> <div class="swiper-container" @mouseenter="stopAutoplay" @mouseleave="startAutoplay"> <div class="swiper-wrapper"> <div class="swiper-slide">Slide 1</div> <div class="swiper-slide">Slide 2</div> <div class="swiper-slide">Slide 3</div> </div> <div class="swiper-pagination"></div> </div> </template> <script> import Swiper from 'swiper' import 'swiper/swiper-bundle.css' export default { mounted() { this.initSwiper() }, methods: { initSwiper() { this.swiper = new Swiper('.swiper-container', { autoplay: { delay: 5000 }, noSwiping: true, pagination: { el: '.swiper-pagination' } }) }, stopAutoplay() { this.swiper.autoplay.stop() }, startAutoplay() { this.swiper.autoplay.start() } } } </script> ``` 在上面的代码中,当鼠标悬浮在轮播上时调用 `stopAutoplay` 方法停止自动轮播,当鼠标离开轮播时调用 `startAutoplay` 方法重新开始自动轮播。同时,使用 `noSwiping` 参数禁止用户手动滑动轮播,只允许通过自动轮播进行切换。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值