` 之前): ```javascript const images = [ { thumb: 'https://fakeimg.pl/100x75/cccccc/909090?text=Image+1', full: 'https://fakeimg.pl/800x600/cccccc/909090?text=Image+1' }, { thumb: 'https://fakeimg.pl/100x75/cccccc/909090?text=Image+2', full: 'https://fakeimg.pl/800x600/cccccc/909090?text=Image+2' }, { thumb: 'https://fakeimg.pl/100x75/cccccc/909090?text=Image+3', full: 'https://fakeimg.pl/800x600/cccccc/909090?text=Image+3' }, { thumb: 'https://fakeimg.pl/100x75/cccccc/909090?text=Image+4', full: 'https://fakeimg.pl/800x600/cccccc/909090?text=Image+4' }, { thumb: 'https://fakeimg.pl/100x75/cccccc/909090?text=Image+5', full: 'https://fakeimg.pl/800x600/cccccc/909090?text=Image+5' } ]; let currentIndex = 0; let intervalId; const mainImage = document.getElementById('mainImage'); const thumbnailContainer = document.getElementById('thumbnailContainer'); function createThumbnails() { images.forEach((img, index) => { const thumbnail = document.createElement('img'); thumbnail.src = img.thumb; thumbnail.alt = `縮圖 ${index + 1}`; thumbnail.className = `thumbnail img-fluid mb-2 ${index === 0 ? 'active' : ''}`; thumbnail.onclick = () => showImage(index); thumbnailContainer.appendChild(thumbnail); }); } function showImage(index) { currentIndex = index; mainImage.src = images[index].full; updateThumbnails(); scrollThumbnail(); } function updateThumbnails() { const thumbnails = thumbnailContainer.getElementsByClassName('thumbnail'); Array.from(thumbnails).forEach((thumb, index) => { thumb.classList.toggle('active', index === currentIndex); }); } function scrollThumbnail() { const activeThumbnail = thumbnailContainer.getElementsByClassName('active')[0]; if (activeThumbnail) { if (window.innerWidth >= 768) { thumbnailContainer.scrollTop = activeThumbnail.offsetTop - thumbnailContainer.offsetTop; } else { thumbnailContainer.scrollLeft = activeThumbnail.offsetLeft - thumbnailContainer.offsetLeft; } } } function startCarousel() { stopCarousel(); intervalId = setInterval(() => { currentIndex = (currentIndex + 1) % images.length; showImage(currentIndex); }, 3000); } function stopCarousel() { if (intervalId) { clearInterval(intervalId); } } function adjustLayout() { const isMobile = window.innerWidth < 768; thumbnailContainer.style.height = isMobile ? 'auto' : `${mainImage.offsetHeight}px`; thumbnailContainer.style.overflowX = isMobile ? 'auto' : 'hidden'; thumbnailContainer.style.overflowY = isMobile ? 'hidden' : 'auto'; thumbnailContainer.style.whiteSpace = isMobile ? 'nowrap' : 'normal'; Array.from(thumbnailContainer.getElementsByClassName('thumbnail')).forEach(thumb => { thumb.style.display = isMobile ? 'inline-block' : 'block'; thumb.style.width = isMobile ? 'auto' : '100%'; thumb.style.height = isMobile ? '75px' : 'auto'; thumb.style.marginRight = isMobile ? '10px' : '0'; }); scrollThumbnail(); } createThumbnails(); showImage(0); startCarousel(); mainImage.addEventListener('load', adjustLayout); window.addEventListener('resize', adjustLayout); thumbnailContainer.addEventListener('mouseenter', stopCarousel); thumbnailContainer.addEventListener('mouseleave', startCarousel); mainImage.addEventListener('mouseenter', stopCarousel); mainImage.addEventListener('mouseleave', startCarousel); ``` 5. 至此,首頁的顯示頁面架構大致完成。