34 lines
1.3 KiB
JavaScript
34 lines
1.3 KiB
JavaScript
/**
|
||
* Bratonien Adventskalender – Türchen-Positionierung (2025)
|
||
* ---------------------------------------------------------
|
||
* Liest data-top / data-left / data-width aus jedem .door
|
||
* und positioniert die Elemente exakt auf dem sichtbaren Bild.
|
||
*/
|
||
|
||
function positionAllDoors() {
|
||
const container = document.querySelector('.kalenderbild');
|
||
const img = container?.querySelector('img');
|
||
if (!container || !img) return;
|
||
|
||
const imgRect = img.getBoundingClientRect();
|
||
const contRect = container.getBoundingClientRect();
|
||
|
||
// alle Türen neu berechnen
|
||
document.querySelectorAll('.door').forEach(door => {
|
||
const topPct = parseFloat(door.dataset.top) || 0;
|
||
const leftPct = parseFloat(door.dataset.left) || 0;
|
||
const widthPct = parseFloat(door.dataset.width) || 10;
|
||
|
||
const doorWidth = imgRect.width * (widthPct / 100);
|
||
|
||
door.style.position = 'absolute';
|
||
door.style.width = doorWidth + 'px';
|
||
door.style.height = doorWidth + 'px';
|
||
door.style.top = (imgRect.top - contRect.top + imgRect.height * (topPct / 100)) + 'px';
|
||
door.style.left = (imgRect.left - contRect.left + imgRect.width * (leftPct / 100)) + 'px';
|
||
});
|
||
}
|
||
|
||
// Positionierung bei Start und Fensteränderung
|
||
window.addEventListener('load', positionAllDoors);
|
||
window.addEventListener('resize', positionAllDoors); |