{% block main %}
<style>
.slider-wrapper {
position: relative;
width: 100%;
height: 200px;
overflow: hidden;
background: #dcdcdc;
}
/* 横スライド */
.slider-track {
display: flex;
width: 500%;
height: 100%;
transition: transform 0.8s ease;
}
/* 各スライド */
.slide {
width: 20%;
height: 100%;
position: relative;
overflow: hidden;
cursor: pointer;
}
/* 縦スライダー */
.vertical-slider {
position: relative;
width: 100%;
height: 100%;
overflow: hidden;
}
.vertical-track {
position: absolute;
width: 100%;
height: 1000%;
top: 0;
left: 0;
animation: scrollY 6s linear infinite;
animation-play-state: paused;
}
.slide:hover .vertical-track {
animation-play-state: running;
}
/* 商品カード */
.item {
width: 100%;
height: 10%;
position: relative;
}
.item a {
display: block;
width: 100%;
height: 100%;
text-decoration: none;
color: #fff;
position: relative;
}
.item img {
width: 100%;
height: 100%;
object-fit: cover;
display: block;
}
/* 型式名 */
.item p {
position: absolute;
bottom: 5px;
left: 50%;
transform: translateX(-50%);
margin: 0;
padding: 2px 10px;
background: #222;
color: #fff;
font-size: 13px;
font-weight: bold;
border-radius: 10px;
}
/* ナビゲーションボタン */
.nav-btn {
position: absolute;
top: 50%;
transform: translateY(-50%);
background: rgba(34, 34, 34, 0.8);
color: #fff;
border: none;
font-size: 20px;
width: 35px;
height: 35px;
cursor: pointer;
z-index: 10;
border-radius: 50%;
transition: background 0.3s;
}
.nav-btn:hover {
background: #000;
}
.prev { left: 10px; }
.next { right: 10px; }
/* ドットナビゲーション */
/* ドットナビゲーション(右下に移動) */
.dots {
position: absolute;
bottom: 8px;
right: 12px; /* ← ここを追加! */
display: flex;
gap: 6px;
transform: none; /* ← 中央寄せを解除 */
}
.dot {
width: 10px;
height: 10px;
border-radius: 50%;
background: #777;
cursor: pointer;
transition: background 0.3s;
}
.dot.active {
background: #222;
}
/* 縦ループ */
@keyframes scrollY {
0% { transform: translateY(0); }
100% { transform: translateY(-50%); }
}
</style>
<div class="slider-wrapper" id="sliderWrapper">
<div class="slider-track" id="sliderTrack">
<!-- === スライド1 === -->
<div class="slide">
<div class="vertical-slider">
<div class="vertical-track">
<div class="item"><a href="#"><img src="https://placehold.jp/300x200.png?text=Cat1-1"><p>HMC-25</p></a></div>
<div class="item"><a href="#"><img src="https://placehold.jp/300x200.png?text=Cat1-2"><p>HMC-50</p></a></div>
<div class="item"><a href="#"><img src="https://placehold.jp/300x200.png?text=Cat1-3"><p>HMC-75</p></a></div>
<div class="item"><a href="#"><img src="https://placehold.jp/300x200.png?text=Cat1-4"><p>HMC-100</p></a></div>
<div class="item"><a href="#"><img src="https://placehold.jp/300x200.png?text=Cat1-5"><p>HMC-150</p></a></div>
<div class="item"><a href="#"><img src="https://placehold.jp/300x200.png?text=Cat1-1"><p>HMC-25</p></a></div>
</div>
</div>
</div>
<!-- === スライド2〜5 === -->
<div class="slide"><div class="vertical-slider"><div class="vertical-track"><div class="item"><a href="#"><img src="https://placehold.jp/300x200.png?text=Cat2-1"><p>HTC-10</p></a></div></div></div></div>
<div class="slide"><div class="vertical-slider"><div class="vertical-track"><div class="item"><a href="#"><img src="https://placehold.jp/300x200.png?text=Cat3-1"><p>HMC-200</p></a></div></div></div></div>
<div class="slide"><div class="vertical-slider"><div class="vertical-track"><div class="item"><a href="#"><img src="https://placehold.jp/300x200.png?text=Cat4-1"><p>HMC-300</p></a></div></div></div></div>
<div class="slide"><div class="vertical-slider"><div class="vertical-track"><div class="item"><a href="#"><img src="https://placehold.jp/300x200.png?text=Cat5-1"><p>HMC-400</p></a></div></div></div></div>
</div>
<button class="nav-btn prev" id="prevBtn">❮</button>
<button class="nav-btn next" id="nextBtn">❯</button>
<div class="dots" id="dots"></div>
</div>
<script>
const track = document.getElementById('sliderTrack');
const slides = document.querySelectorAll('.slide');
const dotsContainer = document.getElementById('dots');
const wrapper = document.getElementById('sliderWrapper');
let current = 0;
let autoSlide;
let resumeTimeout;
// ドット生成
slides.forEach((_, i) => {
const dot = document.createElement('div');
dot.classList.add('dot');
if (i === 0) dot.classList.add('active');
dot.addEventListener('click', () => {
moveTo(i);
pauseAndResume();
});
dotsContainer.appendChild(dot);
});
const dots = document.querySelectorAll('.dot');
// スライド移動
function moveTo(index) {
current = index;
track.style.transform = `translateX(-${index * 20}%)`;
dots.forEach(d => d.classList.remove('active'));
dots[index].classList.add('active');
}
// ボタン
document.getElementById('nextBtn').onclick = () => {
current = (current + 1) % slides.length;
moveTo(current);
pauseAndResume();
};
document.getElementById('prevBtn').onclick = () => {
current = (current - 1 + slides.length) % slides.length;
moveTo(current);
pauseAndResume();
};
// 自動スライド
function startAutoSlide() {
stopAutoSlide();
autoSlide = setInterval(() => {
current = (current + 1) % slides.length;
moveTo(current);
}, 6000);
}
function stopAutoSlide() {
clearInterval(autoSlide);
}
function pauseAndResume() {
stopAutoSlide();
clearTimeout(resumeTimeout);
resumeTimeout = setTimeout(startAutoSlide, 3000);
}
// ホバー停止
wrapper.addEventListener('mouseenter', stopAutoSlide);
wrapper.addEventListener('mouseleave', startAutoSlide);
// === スワイプ対応 ===
let startX = 0;
let isSwiping = false;
wrapper.addEventListener('touchstart', (e) => {
startX = e.touches[0].clientX;
isSwiping = true;
stopAutoSlide();
});
wrapper.addEventListener('touchmove', (e) => {
if (!isSwiping) return;
const diffX = e.touches[0].clientX - startX;
if (Math.abs(diffX) > 50) {
if (diffX > 0) {
current = (current - 1 + slides.length) % slides.length;
} else {
current = (current + 1) % slides.length;
}
moveTo(current);
isSwiping = false;
pauseAndResume();
}
});
wrapper.addEventListener('touchend', () => {
isSwiping = false;
});
// 初期起動
startAutoSlide();
</script>
{% endblock %}