|
document.addEventListener('DOMContentLoaded', (event) => { |
|
// Initialize all Swiper instances on the page |
|
document.querySelectorAll('.swiper').forEach((el) => { |
|
new Swiper(el, { |
|
// Your Swiper options here |
|
// Make sure to include 'autoplay' if you haven't already |
|
autoplay: { |
|
delay: 2500, |
|
disableOnInteraction: false, |
|
}, |
|
}); |
|
|
|
// Set a custom property to track play/pause state |
|
el.swiper.autoplay.paused = false; |
|
}); |
|
|
|
// Add click event listener to all play-pause buttons |
|
document.querySelectorAll('.play-pause-btn').forEach((button) => { |
|
button.addEventListener('click', function () { |
|
// Find the closest Swiper container |
|
var swiperContainer = this.closest('.swiper'); |
|
|
|
// Access the Swiper instance |
|
var swiperInstance = swiperContainer.swiper; |
|
|
|
// Check if autoplay is currently paused |
|
if (swiperInstance.autoplay.paused) { |
|
// If paused, start autoplay |
|
swiperInstance.autoplay.start(); |
|
swiperInstance.autoplay.paused = false; |
|
// Change icon to 'pause' |
|
icon.classList.remove('fa-play'); |
|
icon.classList.add('fa-pause'); |
|
} else { |
|
// If playing, stop autoplay |
|
swiperInstance.autoplay.stop(); |
|
swiperInstance.autoplay.paused = true; |
|
// Change icon to 'play' |
|
icon.classList.remove('fa-pause'); |
|
icon.classList.add('fa-play'); |
|
} |
|
}); |
|
}); |
|
}); |