adventskalender/shared/js/position.js aktualisiert

This commit is contained in:
2025-11-04 20:56:55 +00:00
parent 8921348f4b
commit b17ad3a341

View File

@@ -47,23 +47,22 @@ function positionAllDoors() {
}); });
// Openfields // Openfields
document.querySelectorAll('.openfield').forEach(field => { // Openfields
document.querySelectorAll('.openfield').forEach(field => {
const day = field.dataset.day; const day = field.dataset.day;
const topPct = parseFloat(field.dataset.top) || 0; const topPct = parseFloat(field.dataset.top) || 0;
const leftPct = parseFloat(field.dataset.left) || 0; const leftPct = parseFloat(field.dataset.left) || 0;
const widthPct = parseFloat(field.dataset.width) || 10; const widthPct = parseFloat(field.dataset.width) || 10;
const w = imgRect.width * (widthPct / 100); const w = imgRect.width * (widthPct / 100);
const h = (document.querySelector(`.fluegel[data-day="${day}"]`)) const h = w; // Immer quadratisch egal ob Tür oder Flügeltür
? w * 2 // Doppelt so hoch bei Flügeltür
: w; // Quadratisch bei normaler Tür
field.style.position = 'absolute'; field.style.position = 'absolute';
field.style.width = w + 'px'; field.style.width = w + 'px';
field.style.height = h + 'px'; field.style.height = h + 'px';
field.style.top = (imgRect.top - contRect.top + imgRect.height * (topPct / 100)) + 'px'; field.style.top = (imgRect.top - contRect.top + imgRect.height * (topPct / 100)) + 'px';
field.style.left = (imgRect.width * (leftPct / 100) + (contRect.width - imgRect.width) / 2) + 'px'; field.style.left = (imgRect.width * (leftPct / 100) + (contRect.width - imgRect.width) / 2) + 'px';
}); });
} }
window.addEventListener('load', positionAllDoors); window.addEventListener('load', positionAllDoors);