Skip to content

Instantly share code, notes, and snippets.

@SomeNiceCode
Created July 1, 2025 19:21
Show Gist options
  • Save SomeNiceCode/781934f08a3f3d7e518d8e12ffa39a66 to your computer and use it in GitHub Desktop.
Save SomeNiceCode/781934f08a3f3d7e518d8e12ffa39a66 to your computer and use it in GitHub Desktop.
Dz events
const images = [
"https://bigfoto.name/uploads/posts/2022-01/1641988718_10-bigfoto-name-p-polirovannii-beton-v-interere-22.jpg",
"https://tse2.mm.bing.net/th/id/OIP.GhCdwqjnQ_4lDbolnBlTRgHaEK?rs=1&pid=ImgDetMain&o=7&rm=3",
"https://klike.net/uploads/posts/2019-11/1574510006_2.jpg"
];
let currentIndex = 0;
const imgElement = document.getElementById("gallery-image");
const prevButton = document.getElementById("prev-button");
const nextButton = document.getElementById("next-button");
function updateGallery() {
imgElement.src = images[currentIndex];
prevButton.disabled = currentIndex === 0;
nextButton.disabled = currentIndex === images.length - 1;
}
prevButton.addEventListener("click", () => {
if (currentIndex > 0) {
currentIndex--;
updateGallery();
}
});
nextButton.addEventListener("click", () => {
if (currentIndex < images.length - 1) {
currentIndex++;
updateGallery();
}
});
updateGallery();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment