document.addEventListener('DOMContentLoaded', () => { const isPC = window.innerWidth > 768; // 通常スライダーの設定 const options = { autoplay: false, type: "loop", pauseOnHover: false, pauseOnFocus: false, interval: 6000, speed: 2000, arrows: true, pagination: true, }; const targets = ['.splide01', '.splide02', '.splide03']; targets.forEach(selector => { const el = document.querySelector(selector); if (el) { const splide = new Splide(el, options).mount(); // 手動操作後に autoplay をリセット splide.on('move', () => { splide.Components.Autoplay.pause(); splide.Components.Autoplay.play(); }); // PC時のみ Intersection Observer で画面に入ったら再生 if (isPC) { const observer = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting) { splide.Components.Autoplay.play(); observer.unobserve(entry.target); // 一度だけ起動 } }); }, { threshold: 0.3 // 30%見えたら起動 }); observer.observe(el); } } }); // kanko-splide01 の設定(autoScroll 拡張付き) const kankoEl = document.querySelector('.kanko-splide01'); if (kankoEl) { const kankoSplide = new Splide(kankoEl, { type: 'loop', perPage: 5, gap: '0rem', arrows: false, pagination: false, drag: false, autoScroll: { speed: 0.5, pauseOnHover: false, pauseOnFocus: false, rewind: false, }, breakpoints: { 768: { perPage: 2, }, }, }); kankoSplide.mount(window.splide.Extensions); } });