Last active
September 18, 2018 10:02
-
-
Save zoxon/a8577914fdedfec36773e020e48a057f to your computer and use it in GitHub Desktop.
Swiper.js - stop autoplay on hover and start on blur
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sliderElement = document.querySelector(".main-slider"); | |
if (sliderElement) { | |
const slider = new Swiper(".swiper-container", { | |
slidesPerView: 1, | |
spaceBetween: 0, | |
watchOverflow: true, | |
loop: true, | |
autoplay: { | |
delay: 4000, | |
disableOnInteraction: false | |
}, | |
pagination: { | |
el: ".swiper-pagination" | |
} | |
}); | |
["mouseenter", "mouseleave"].forEach(eventName => | |
sliderElement.addEventListener( | |
eventName, | |
() => { | |
slider.autoplay.running | |
? slider.autoplay.stop() | |
: slider.autoplay.start(); | |
}, | |
false | |
) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment