(() => { // webpackBootstrap const { actions } = ShopbySkin; const bannerId = document.currentScript.getAttribute('shopby-banner-id'); if (bannerId) { actions?.getBannerById?.({ bannerId }); } })(); $(document).ready(() => { setTimeout(() => { var slideSetting2 = { slidesPerView: 2, spaceBetween: 20, //loop: true, speed: 800, // 배너 데이터가 500ms 이후 늦게 들어와도 자동으로 다시 계산하도록 observer: true, observeParents: true, autoplay: { delay: 3000, disableOnInteraction: false, pauseOnMouseEnter: true, }, navigation: { nextEl: '.mcon04 .swiper-button-next', prevEl: '.mcon04 .swiper-button-prev', }, // on: { // init: function () { // this.loopFix(); // const activeSwiper = this; // ← 변경된 부분 // const originalSlides = activeSwiper.slides.filter(slide => // !slide.classList.contains('swiper-slide.duplicate') // ); // // 슬라이드 수가 적을 경우 복제 // if (originalSlides.length < 4) { // for (let j = 0; j < 3; j++) { // originalSlides.forEach((slide) => { // const cloned = slide.cloneNode(true); // cloned.classList.add('duplicated'); // activeSwiper.wrapperEl.appendChild(cloned); // }); // } // activeSwiper.update(); // } // } // }, }; const initBenefitSwiper = () => { const swiperEl = document.querySelector('.mcon04 .swiper'); if (!swiperEl) return false; // 배너 데이터가 아직 안 그려짐 if (swiperEl.swiper) return true; // 이미 초기화됨 if (!swiperEl.querySelector('.swiper-slide')) return false; // 슬라이드 아직 없음 new Swiper(swiperEl, slideSetting2); return true; }; // .swiper가 (느린 네트워크 등으로) 늦게 생겨도 잡히도록 DOM 변화를 감지해 init if (!initBenefitSwiper()) { const observer = new MutationObserver(() => { if (initBenefitSwiper()) observer.disconnect(); }); observer.observe(document.body, { childList: true, subtree: true }); // 안전장치: 30초 안에도 안 그려지면 관찰 중단 (메모리 누수 방지) setTimeout(() => observer.disconnect(), 30000); } }, 500); });