adventskalender/shared/js/position.js aktualisiert
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Bratonien Adventskalender – Türchen-Positionierung (2025)
|
||||
* ---------------------------------------------------------
|
||||
* Liest data-top / data-left / data-width aus jedem .door
|
||||
* Liest data-top / data-left / data-width aus jedem .door und .openfield
|
||||
* und positioniert die Elemente exakt auf dem sichtbaren Bild.
|
||||
*/
|
||||
|
||||
@@ -13,17 +13,31 @@ function positionAllDoors() {
|
||||
const imgRect = img.getBoundingClientRect();
|
||||
const contRect = cont.getBoundingClientRect();
|
||||
|
||||
// alle Türchen positionieren
|
||||
document.querySelectorAll('.door').forEach(door => {
|
||||
const day = door.dataset.day;
|
||||
const topPct = parseFloat(door.dataset.top) || 0;
|
||||
const leftPct = parseFloat(door.dataset.left) || 0;
|
||||
const widthPct = parseFloat(door.dataset.width) || 10;
|
||||
|
||||
const w = imgRect.width * (widthPct / 100);
|
||||
|
||||
// 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';
|
||||
|
||||
// passendes openfield finden und synchron positionieren
|
||||
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;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user