|
| 1 | +// Kontext-Style main functionality |
| 2 | +document.addEventListener('DOMContentLoaded', function() { |
| 3 | + // 移除了模态框功能,现在只保留图片导航 |
| 4 | + |
| 5 | + // 图片导航功能 |
| 6 | + function initImageNavigation() { |
| 7 | + document.querySelectorAll('.style-display').forEach(display => { |
| 8 | + const container = display.querySelector('.style-container'); |
| 9 | + const images = Array.from(container.querySelectorAll('.style-image')); |
| 10 | + const prevBtn = display.querySelector('.prev-btn'); |
| 11 | + const nextBtn = display.querySelector('.next-btn'); |
| 12 | + const currentSlideSpan = display.querySelector('.current-slide'); |
| 13 | + const totalSlidesSpan = display.querySelector('.total-slides'); |
| 14 | + |
| 15 | + if (images.length === 0) return; |
| 16 | + |
| 17 | + let currentIndex = 0; |
| 18 | + |
| 19 | + function showImage(index) { |
| 20 | + images.forEach(img => img.classList.remove('active')); |
| 21 | + images[index].classList.add('active'); |
| 22 | + |
| 23 | + currentSlideSpan.textContent = index + 1; |
| 24 | + totalSlidesSpan.textContent = images.length; |
| 25 | + |
| 26 | + prevBtn.disabled = index === 0; |
| 27 | + nextBtn.disabled = index === images.length - 1; |
| 28 | + |
| 29 | + currentIndex = index; |
| 30 | + } |
| 31 | + |
| 32 | + prevBtn.addEventListener('click', () => { |
| 33 | + if (currentIndex > 0) { |
| 34 | + showImage(currentIndex - 1); |
| 35 | + } |
| 36 | + }); |
| 37 | + |
| 38 | + nextBtn.addEventListener('click', () => { |
| 39 | + if (currentIndex < images.length - 1) { |
| 40 | + showImage(currentIndex + 1); |
| 41 | + } |
| 42 | + }); |
| 43 | + |
| 44 | + // 键盘导航 |
| 45 | + display.addEventListener('keydown', (e) => { |
| 46 | + if (e.key === 'ArrowLeft' && currentIndex > 0) prevBtn.click(); |
| 47 | + if (e.key === 'ArrowRight' && currentIndex < images.length - 1) nextBtn.click(); |
| 48 | + }); |
| 49 | + |
| 50 | + // 初始化显示 |
| 51 | + showImage(0); |
| 52 | + }); |
| 53 | + } |
| 54 | + |
| 55 | + // 当前版本未使用自动画廊 |
| 56 | + |
| 57 | + // 初始化 |
| 58 | + initImageNavigation(); |
| 59 | + // initAutoGallery 已禁用 |
| 60 | +}); |
0 commit comments