var mySwiper = new Swiper('.swiper-container', { autoplay: { disableOnInteraction: false, delay: 2500, }, preventLinksPropagation: false, // 阻止點擊事件冒泡 speed: 500, loop: true, // 若是須要分頁器 pagination: { el: '.swiper-pagination', }, // 若是須要前進後退按鈕 navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev', }, onSlideChangeEnd: function (swiper) { // pagination BUG var activeIndex = swiper.activeIndex; $('.swiper-pagination') .find('span') .eq(activeIndex) .addClass('swiper-pagination-bullet-active') .siblings() .removeClass('swiper-pagination-bullet-active'); } }); // 鼠標移入中止自動滾動 $('.swiper-slide').mouseenter(function() { mySwiper.autoplay.stop(); }) // 鼠標移出開始自動滾動 $('.swiper-slide').mouseleave(function() { mySwiper.autoplay.start(); })