From 4e57b9d406526119a196c7e7bd2c926a35ea1bb0 Mon Sep 17 00:00:00 2001 From: Thomas Dannenberg Date: Tue, 4 Nov 2025 17:39:18 +0000 Subject: [PATCH] adventskalender/shared/js/position.js aktualisiert --- adventskalender/shared/js/position.js | 51 +++++++++++++++++---------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/adventskalender/shared/js/position.js b/adventskalender/shared/js/position.js index ffb0543..5ed4bf5 100644 --- a/adventskalender/shared/js/position.js +++ b/adventskalender/shared/js/position.js @@ -1,11 +1,11 @@ /** - * Bratonien Adventskalender – Türchen-Positionierung (2025) + * Bratonien Adventskalender – Positionierung aller Türchen und Flügel (2025) * --------------------------------------------------------- - * Liest data-top / data-left / data-width aus jedem .door und .openfield - * und positioniert die Elemente exakt auf dem sichtbaren Bild. + * Liest data-top / data-left / data-width aus allen relevanten Elementen + * und positioniert sie exakt auf dem sichtbaren Hintergrundbild. */ -function positionAllDoors() { +function positionAllElements() { const cont = document.querySelector('.kalenderbild'); const img = cont?.querySelector('img'); if (!cont || !img) return; @@ -13,7 +13,7 @@ function positionAllDoors() { const imgRect = img.getBoundingClientRect(); const contRect = cont.getBoundingClientRect(); - // alle Türchen positionieren + // === Einzeltüren & Openfields === document.querySelectorAll('.door').forEach(door => { const day = door.dataset.day; const topPct = parseFloat(door.dataset.top) || 0; @@ -21,37 +21,52 @@ function positionAllDoors() { const widthPct = parseFloat(door.dataset.width) || 10; const w = imgRect.width * (widthPct / 100); + const t = imgRect.top - contRect.top + imgRect.height * (topPct / 100); + const l = imgRect.width * (leftPct / 100) + (contRect.width - imgRect.width) / 2; - // Tür positionieren door.style.position = 'absolute'; door.style.width = w + 'px'; door.style.height = w + 'px'; - door.style.top = (imgRect.top - contRect.top + imgRect.height * (topPct / 100)) + 'px'; - door.style.left = (imgRect.width * (leftPct / 100) + (contRect.width - imgRect.width) / 2) + 'px'; + door.style.top = t + 'px'; + door.style.left = l + 'px'; - // passendes openfield finden und synchron positionieren - const field = document.querySelector(.openfield[data-day="${day}"]); + const field = document.querySelector(`.openfield[data-day="${day}"]`); if (field) { field.style.position = 'absolute'; field.style.width = w + 'px'; field.style.height = w + 'px'; - field.style.top = door.style.top; - field.style.left = door.style.left; + field.style.top = t + 'px'; + field.style.left = l + 'px'; } }); + + // === Flügel (linke und rechte Seite) === + document.querySelectorAll('.fluegel').forEach(flugel => { + const topPct = parseFloat(flugel.dataset.top) || 0; + const leftPct = parseFloat(flugel.dataset.left) || 0; + const widthPct = parseFloat(flugel.dataset.width) || 5; + + const w = imgRect.width * (widthPct / 100); + const t = imgRect.top - contRect.top + imgRect.height * (topPct / 100); + const l = imgRect.width * (leftPct / 100) + (contRect.width - imgRect.width) / 2; + + flugel.style.position = 'absolute'; + flugel.style.width = w + 'px'; + flugel.style.height = w + 'px'; + flugel.style.top = t + 'px'; + flugel.style.left = l + 'px'; + }); } -window.addEventListener('load', positionAllDoors); -window.addEventListener('resize', positionAllDoors); +window.addEventListener('load', positionAllElements); +window.addEventListener('resize', positionAllElements); -// iOS / Mobile: neu berechnen bei Drehung oder Wake-up window.addEventListener('orientationchange', () => { - setTimeout(positionAllDoors, 300); // kleiner Delay für Safari + setTimeout(positionAllElements, 300); }); -// optional: neu positionieren, wenn die Seite wieder aktiv wird document.addEventListener('visibilitychange', () => { if (document.visibilityState === 'visible') { - setTimeout(positionAllDoors, 200); + setTimeout(positionAllElements, 200); } }); \ No newline at end of file