home > slideshow : skip desktop-only slides on mobile (< 1000px)

Closes #8

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
isUnknown 2026-06-05 18:40:03 +02:00
parent 73fb7d2fd5
commit 4490e11794
4 changed files with 39 additions and 13 deletions

View file

@ -1,18 +1,38 @@
const slideshow = document.getElementById('home-slideshow');
const slideshow = document.getElementById("home-slideshow");
if (slideshow) {
const items = [...slideshow.querySelectorAll('.slide')];
const prev = slideshow.querySelector('.prev');
const next = slideshow.querySelector('.next');
const items = [...slideshow.querySelectorAll(".slide")];
const prev = slideshow.querySelector(".prev");
const next = slideshow.querySelector(".next");
let current = 0;
function goTo(index) {
items[current].classList.remove('active');
current = (index + items.length) % items.length;
items[current].classList.add('active');
function isDesktopOnly(index) {
return (
window.innerWidth < 1000 &&
items[index].classList.contains("desktop-only")
);
}
items[0]?.classList.add('active');
prev?.addEventListener('click', () => goTo(current - 1));
next?.addEventListener('click', () => goTo(current + 1));
function findNext(from, direction) {
let index = (from + direction + items.length) % items.length;
let steps = 0;
while (isDesktopOnly(index) && steps < items.length) {
index = (index + direction + items.length) % items.length;
steps++;
}
return index;
}
function goTo(index) {
items[current].classList.remove("active");
current = index;
items[current].classList.add("active");
}
const firstVisible = findNext(-1, 1);
items[firstVisible]?.classList.add("active");
current = firstVisible;
prev?.addEventListener("click", () => goTo(findNext(current, -1)));
next?.addEventListener("click", () => goTo(findNext(current, 1)));
}