1. 程式人生 > >swiper滑鼠放上停止輪播事件

swiper滑鼠放上停止輪播事件

var mySwiper = new Swiper('.swiper-container', {
      spaceBetween: 30,
      centeredSlides: true,
      loop: true, //迴圈播放
      autoplay: { //播放時間間隔
        delay: 5000,
        disableOnInteraction: false,
      },
      pagination: {
        el: '.swiper-pagination',
        clickable: true,
      },
      // navigation: {
      //   nextEl: '.swiper-button-next',
      //   prevEl: '.swiper-button-prev',
      // },
    });
    mySwiper.el.onmouseover = function(){ //滑鼠放上暫停輪播
      mySwiper.autoplay.stop();
    }
    mySwiper.el.onmouseleave = function(){
      mySwiper.autoplay.start();
    }