<!DOCTYPE html>
Local Photo Album
<img id="current-photo" src="/gallery/images/1.jpg" alt="deep night">
</div>
<div>
<button id="prev-button">Previous</button>
<button id="next-button">Next</button>
</div>
<script>
// 图片数组,根据你提供的信息
const photos = [
"/gallery/images/1.jpg",
"/gallery/images/2.jpg",
"/gallery/images/3.jpg",
"/gallery/images/4.jpg",
"/gallery/images/5.jpg",
"/gallery/images/6.jpg",
"/gallery/images/7.jpg",
"/gallery/images/8.jpg",
"/gallery/images/9.jpg",
"/gallery/images/10.jpg",
"/gallery/images/11.jpg",
"/gallery/images/12.jpg",
"/gallery/images/13.jpg",
"/gallery/images/14.jpg",
"/gallery/images/15.jpg",
"/gallery/images/16.jpg",
"/gallery/images/17.jpg",
"/gallery/images/18.jpg"
];
let currentIndex = 0;
const currentPhoto = document.getElementById('current-photo');
const prevButton = document.getElementById('prev-button');
const nextButton = document.getElementById('next-button');
// 更新图片显示
function updatePhoto() {
currentPhoto.src = photos[currentIndex];
}
// 上一张按钮点击事件
prevButton.addEventListener('click', () => {
currentIndex = (currentIndex - 1 + photos.length) % photos.length;
updatePhoto();
});
// 下一张按钮点击事件
nextButton.addEventListener('click', () => {
currentIndex = (currentIndex + 1) % photos.length;
updatePhoto();
});
</script>