My portfolio, where I cook up projects.
A collection of games, books and resources I enjoy.
About me - what fuels my journey.
The Problem - I needed gallery for my website
Solution - JavaScript Gallery - my first creation in this language!
let index = 0;
const images = document.querySelectorAll('.carousel-image');
const prevButton = document.querySelector('.prev-btn');
const nextButton = document.querySelector('.next-btn');
function showImage(idx) {
images.forEach((image, i) => {
image.classList.remove('active');
if (i === idx) {
image.classList.add('active');
}
});
}
function nextImage() {
index = (index + 1) % images.length;
showImage(index);
}
function prevImage() {
index = (index - 1 + images.length) % images.length;
showImage(index);
}
nextButton.addEventListener('click', nextImage);
prevButton.addEventListener('click', prevImage);
showImage(index);