📝 구현 코드
JavaScript
var swiper = new Swiper(".mySwiper", {
slidesPerView: 1,
spaceBetween: 30,
loop: true,
autoplay: {
delay: 3000, // 3초마다 넘어감
disableOnInteraction: false, // 사용자 조작 후에도 자동재생 유지
},
pagination: {
el: ".swiper-pagination",
clickable: true,
},
navigation: {
nextEl: ".swiper-button-next",
prevEl: ".swiper-button-prev",
},
});
// 자동재생 제어 함수들
function toggleAutoplay() {
if (swiper.autoplay.running) {
swiper.autoplay.stop();
} else {
swiper.autoplay.start();
}
}
function restartAutoplay() {
swiper.autoplay.start();
}