Mode:
Duration:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
document.addEventListener('DOMContentLoaded', () => {
const images = document.querySelectorAll('.slide') as NodeListOf<HTMLImageElement>;
let index = 0;
const nextBtn = document.getElementById('next') as HTMLButtonElement;
const prevBtn = document.getElementById('prev') as HTMLButtonElement;
function show(i: number) {
images.forEach(img => img.style.display = 'none');
images[i].style.display = 'block';
}
nextBtn.addEventListener('click', () => { index = (index + 1) % images.length; show(index); });
prevBtn.addEventListener('click', () => { index = (index - 1 + images.length) % images.length; show(index); });
show(index);
});Coding works best on desktop or with an external keyboard.