(function ($) {
function setStartingSlide($scope) {
const widget = $scope[0];
const host = widget.closest('[class*="banner-start-"]');
if (!host) return;
const match = [...host.classList]
.map(className => className.match(/^banner-start-(\d+)$/))
.find(Boolean);
if (!match) return;
// banner-start-4 means the fourth slide.
const slideIndex = Math.max(0, Number(match[1]) - 1);
const swiperElement = widget.querySelector(
'.elementor-slides-wrapper, .swiper'
);
let attempts = 0;
function moveToStartingSlide() {
const swiper = swiperElement?.swiper;
if (!swiper && attempts++ < 60) {
requestAnimationFrame(moveToStartingSlide);
return;
}
if (!swiper) return;
if (swiper.params.loop && typeof swiper.slideToLoop === 'function') {
swiper.slideToLoop(slideIndex, 0, false);
} else {
swiper.slideTo(slideIndex, 0, false);
}
}
moveToStartingSlide();
}
$(window).on('elementor/frontend/init', function () {
elementorFrontend.hooks.addAction(
'frontend/element_ready/slides.default',
setStartingSlide
);
});
})(jQuery);