FIRE

Inferno Kitchen

My portfolio, where I cook up projects.

CHILL

Chill Shelf

A collection of games, books and resources I enjoy.

HEAT

Flavor Core

About me - what fuels my journey.

The Gallery

The Problem - I needed gallery for my website

Solution - JavaScript Gallery - my first creation in this language!

Code (JavaScript):

chilisquad@code-snacks:~$
			
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);
            
		

Demo:

Gallery