Design Stufe 2: Tipp-Karten zum Umdrehen, Sommer/Winter-Vergleich, Galerie mit weichem Vergroessern
Deploy FeWo mit PipelineManager / deploy (push) Successful in 3m45s
Deploy FeWo mit PipelineManager / deploy (push) Successful in 3m45s
- Baustein "Ausflugstipps" (tips): Karten mit Foto vorne, Tipp/Weg/beste Zeit hinten; Seebad als Ansichtskarten - Baustein "Sommer/Winter-Vergleich" (compare): Trennlinie ziehen, Tastatur ueber Range-Input, einmaliger Hinweis-Schwenk - Lightbox: Foto waechst aus der Vorschau, Blaettern (Pfeile, Tasten, Wischen), Zaehler, Bildunterschrift; partials/lightbox - Bewegung reduzieren: Ueberblenden statt Drehen, kein Schwenk, keine Zoom-Animation Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c8bb0f6e97
commit
4c9e6992f4
20 files changed
+785
-43
No files matched your search
@@ -2,32 +2,137 @@
|
||||
* Theme "Ostsee-Licht": small progressive enhancements. Everything works without JavaScript.
|
||||
*/
|
||||
|
||||
// Lightbox for galleries: links with data-lightbox open the large image in a <dialog>.
|
||||
document.addEventListener('click', (event) => {
|
||||
const link = event.target.closest('a[data-lightbox]');
|
||||
if (!link) {
|
||||
return;
|
||||
}
|
||||
// Lightbox for galleries: links with data-lightbox open the large image in the layout's dialog#lightbox. The photo
|
||||
// grows out of its thumbnail and shrinks back on closing; the links of one section form a series to browse with the
|
||||
// arrow buttons, the arrow keys or a swipe. Without JavaScript the link simply opens the large image.
|
||||
const lightbox = document.getElementById('lightbox');
|
||||
if (lightbox && typeof lightbox.showModal === 'function') {
|
||||
const image = lightbox.querySelector('img');
|
||||
const caption = lightbox.querySelector('[data-caption]');
|
||||
const counter = lightbox.querySelector('[data-counter]');
|
||||
const browseButtons = lightbox.querySelectorAll('[data-prev], [data-next]');
|
||||
const ease = 'cubic-bezier(0.2, 0.8, 0.2, 1)';
|
||||
let series = [];
|
||||
let index = 0;
|
||||
|
||||
const dialog = document.getElementById('lightbox');
|
||||
if (!dialog || typeof dialog.showModal !== 'function') {
|
||||
return;
|
||||
}
|
||||
const thumbnailOf = (link) => link.querySelector('img');
|
||||
|
||||
event.preventDefault();
|
||||
const image = dialog.querySelector('img');
|
||||
image.src = link.href;
|
||||
image.alt = link.dataset.alt ?? '';
|
||||
dialog.querySelector('[data-caption]').textContent = link.dataset.alt ?? '';
|
||||
dialog.showModal();
|
||||
});
|
||||
// Transform that lays the opened image over the thumbnail: same centre, scaled to cover it, cropped like object-cover.
|
||||
const fromThumbnail = (thumbnail) => {
|
||||
const from = thumbnail.getBoundingClientRect();
|
||||
const to = image.getBoundingClientRect();
|
||||
if (!from.width || !to.width) {
|
||||
return null;
|
||||
}
|
||||
const scale = Math.max(from.width / to.width, from.height / to.height);
|
||||
const insetX = (to.width * scale - from.width) / (2 * scale);
|
||||
const insetY = (to.height * scale - from.height) / (2 * scale);
|
||||
const x = from.left + from.width / 2 - (to.left + to.width / 2);
|
||||
const y = from.top + from.height / 2 - (to.top + to.height / 2);
|
||||
|
||||
document.addEventListener('click', (event) => {
|
||||
const dialog = event.target.closest('dialog#lightbox');
|
||||
if (dialog && (event.target === dialog || event.target.closest('[data-close]'))) {
|
||||
dialog.close();
|
||||
}
|
||||
});
|
||||
return { transform: `translate(${x}px, ${y}px) scale(${scale})`, clipPath: `inset(${insetY}px ${insetX}px round 4px)` };
|
||||
};
|
||||
|
||||
const visible = (element) => {
|
||||
const rect = element.getBoundingClientRect();
|
||||
return rect.bottom > 0 && rect.top < window.innerHeight && rect.width > 0;
|
||||
};
|
||||
|
||||
const show = (position) => {
|
||||
index = (position + series.length) % series.length;
|
||||
const link = series[index];
|
||||
const thumbnail = thumbnailOf(link);
|
||||
image.src = thumbnail?.currentSrc || link.href;
|
||||
image.alt = link.dataset.alt ?? '';
|
||||
caption.textContent = link.dataset.caption || link.dataset.alt || '';
|
||||
if (counter) {
|
||||
counter.textContent = series.length > 1 ? `${index + 1} von ${series.length}` : '';
|
||||
}
|
||||
if (image.src !== link.href) {
|
||||
const large = new Image();
|
||||
large.onload = () => { if (series[index] === link) image.src = link.href; };
|
||||
large.src = link.href;
|
||||
}
|
||||
};
|
||||
|
||||
const browse = (step) => {
|
||||
if (series.length < 2) {
|
||||
return;
|
||||
}
|
||||
show(index + step);
|
||||
if (!reducedMotion()) {
|
||||
image.animate([{ opacity: 0, transform: `translateX(${step * 2.5}rem)` }, { opacity: 1, transform: 'none' }], { duration: 320, easing: ease });
|
||||
}
|
||||
};
|
||||
|
||||
const close = () => {
|
||||
const thumbnail = thumbnailOf(series[index] ?? lightbox);
|
||||
const start = !reducedMotion() && thumbnail && visible(thumbnail) ? fromThumbnail(thumbnail) : null;
|
||||
if (!start) {
|
||||
lightbox.close();
|
||||
return;
|
||||
}
|
||||
lightbox.querySelectorAll('[data-chrome]').forEach((element) => element.animate([{ opacity: 1 }, { opacity: 0 }], { duration: 150, fill: 'forwards' }));
|
||||
image.animate([{ transform: 'none', clipPath: 'inset(0 0 round 4px)' }, start], { duration: 380, easing: ease, fill: 'forwards' })
|
||||
.finished.then(() => {
|
||||
lightbox.close();
|
||||
lightbox.getAnimations({ subtree: true }).forEach((animation) => animation.cancel());
|
||||
});
|
||||
};
|
||||
|
||||
document.addEventListener('click', (event) => {
|
||||
const link = event.target.closest('a[data-lightbox]');
|
||||
if (!link) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
series = [...(link.closest('section') ?? document).querySelectorAll('a[data-lightbox]')];
|
||||
browseButtons.forEach((button) => { button.hidden = series.length < 2; });
|
||||
show(series.indexOf(link));
|
||||
lightbox.showModal();
|
||||
|
||||
const thumbnail = thumbnailOf(link);
|
||||
const start = !reducedMotion() && thumbnail ? fromThumbnail(thumbnail) : null;
|
||||
if (start) {
|
||||
image.animate([start, { transform: 'none', clipPath: 'inset(0 0 round 4px)' }], { duration: 480, easing: ease });
|
||||
lightbox.querySelectorAll('[data-chrome]').forEach((element) => element.animate([{ opacity: 0 }, { opacity: 1 }], { duration: 250, delay: 300, fill: 'backwards' }));
|
||||
}
|
||||
});
|
||||
|
||||
lightbox.addEventListener('click', (event) => {
|
||||
if (event.target.closest('[data-prev]')) {
|
||||
browse(-1);
|
||||
} else if (event.target.closest('[data-next]')) {
|
||||
browse(1);
|
||||
} else if (event.target === lightbox || event.target.closest('[data-close]')) {
|
||||
close();
|
||||
}
|
||||
});
|
||||
|
||||
lightbox.addEventListener('cancel', (event) => {
|
||||
event.preventDefault();
|
||||
close();
|
||||
});
|
||||
|
||||
lightbox.addEventListener('keydown', (event) => {
|
||||
if (event.key === 'ArrowLeft' || event.key === 'ArrowRight') {
|
||||
event.preventDefault();
|
||||
browse(event.key === 'ArrowLeft' ? -1 : 1);
|
||||
}
|
||||
});
|
||||
|
||||
let swipeStart = null;
|
||||
lightbox.addEventListener('pointerdown', (event) => { swipeStart = { x: event.clientX, y: event.clientY }; });
|
||||
lightbox.addEventListener('pointerup', (event) => {
|
||||
const dx = swipeStart ? event.clientX - swipeStart.x : 0;
|
||||
const dy = swipeStart ? event.clientY - swipeStart.y : 0;
|
||||
swipeStart = null;
|
||||
if (Math.abs(dx) > 50 && Math.abs(dx) > Math.abs(dy) * 1.5) {
|
||||
browse(dx < 0 ? 1 : -1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Availability search in the hero: forwards the dates to the booking page.
|
||||
document.addEventListener('submit', (event) => {
|
||||
@@ -171,3 +276,84 @@ if (!reducedMotion() && 'IntersectionObserver' in window) {
|
||||
reveal.observe(element);
|
||||
});
|
||||
}
|
||||
|
||||
// Cards to turn over (sections/tips): [data-flip] card, [data-flip-inner], [data-flip-face="front|back"], buttons
|
||||
// [data-flip-toggle] (hidden without JavaScript). The hidden face is inert, so keyboard and screen reader stay on the
|
||||
// visible one; focus moves to the button of the face that turns up.
|
||||
document.querySelectorAll('[data-flip]').forEach((card) => {
|
||||
const front = card.querySelector('[data-flip-face="front"]');
|
||||
const back = card.querySelector('[data-flip-face="back"]');
|
||||
const turn = (flipped) => {
|
||||
card.toggleAttribute('data-flipped', flipped);
|
||||
front.inert = flipped;
|
||||
back.inert = !flipped;
|
||||
card.querySelectorAll('[data-flip-toggle]').forEach((button) => button.setAttribute('aria-expanded', String(flipped)));
|
||||
(flipped ? back : front).querySelector('[data-flip-toggle]')?.focus({ preventScroll: true });
|
||||
};
|
||||
|
||||
card.dataset.flip = 'ready';
|
||||
back.inert = true;
|
||||
card.querySelectorAll('[data-flip-toggle]').forEach((button) => {
|
||||
button.hidden = false;
|
||||
button.addEventListener('click', () => turn(!card.hasAttribute('data-flipped')));
|
||||
});
|
||||
});
|
||||
|
||||
// Season comparison (sections/compare): dragging or tapping moves the dividing line, the hidden range input
|
||||
// ([data-compare-range]) does the same by keyboard. Once in view, the line sweeps briefly to show it can be moved.
|
||||
document.querySelectorAll('[data-compare]').forEach((box) => {
|
||||
const range = box.querySelector('[data-compare-range]');
|
||||
let touched = false;
|
||||
const set = (percent) => {
|
||||
const value = Math.min(100, Math.max(0, percent));
|
||||
box.style.setProperty('--split', `${value}%`);
|
||||
range.value = String(Math.round(value));
|
||||
};
|
||||
const fromPointer = (event) => {
|
||||
const rect = box.getBoundingClientRect();
|
||||
set(((event.clientX - rect.left) / rect.width) * 100);
|
||||
};
|
||||
|
||||
range.hidden = false;
|
||||
range.addEventListener('input', () => { touched = true; set(Number(range.value)); });
|
||||
box.addEventListener('pointerdown', (event) => {
|
||||
touched = true;
|
||||
box.setPointerCapture(event.pointerId);
|
||||
fromPointer(event);
|
||||
});
|
||||
box.addEventListener('pointermove', (event) => {
|
||||
if (box.hasPointerCapture(event.pointerId)) {
|
||||
fromPointer(event);
|
||||
}
|
||||
});
|
||||
|
||||
if (reducedMotion() || !('IntersectionObserver' in window)) {
|
||||
return;
|
||||
}
|
||||
const hint = new IntersectionObserver(([entry]) => {
|
||||
if (!entry.isIntersecting) {
|
||||
return;
|
||||
}
|
||||
hint.disconnect();
|
||||
const keys = [[0, 50], [0.35, 68], [0.75, 34], [1, 50]];
|
||||
const duration = 2200;
|
||||
let begin = null;
|
||||
const step = (time) => {
|
||||
if (touched) {
|
||||
return;
|
||||
}
|
||||
begin ??= time;
|
||||
const t = Math.min(1, (time - begin) / duration);
|
||||
const k = keys.findIndex(([at]) => at >= t);
|
||||
const [t0, v0] = keys[Math.max(0, k - 1)];
|
||||
const [t1, v1] = keys[k];
|
||||
const local = t1 === t0 ? 1 : (t - t0) / (t1 - t0);
|
||||
set(v0 + (v1 - v0) * (0.5 - Math.cos(Math.PI * local) / 2));
|
||||
if (t < 1) {
|
||||
requestAnimationFrame(step);
|
||||
}
|
||||
};
|
||||
setTimeout(() => requestAnimationFrame(step), 400);
|
||||
}, { threshold: 0.6 });
|
||||
hint.observe(box);
|
||||
});
|
||||
Reference in new issue
Block a user