I haven’t used Swiper in a while, and while setting it up this time, I noticed the slider was not playing automatically. After some investigation it appeared to need some modules, loaded from swiper/modules.
I’m using @wordpress/scripts
with the watch
command, like below:
wp-scripts start ./assets/src/js/index.js --output-path=./assets/dist/js/
The slider works beautifully with the following snippet:
// import Swiper JS
import Swiper from 'swiper';
import { Navigation, Autoplay } from 'swiper/modules';
Swiper.use([Navigation, Autoplay]);
document.addEventListener('DOMContentLoaded', () => {
const swiper = new Swiper('.swiper', {
loop: true,
autoplay: {
delay: 2500,
disableOnInteraction: false,
},
speed: 1000,
navigation: {
nextEl: ".swiper-button-next",
prevEl: ".swiper-button-prev",
},
});
});
Leave a Reply