adventskalender/shared/js/position.js aktualisiert
This commit is contained in:
@@ -1,10 +1,3 @@
|
||||
/**
|
||||
* Bratonien Adventskalender – Türchen-Positionierung (2025)
|
||||
* ---------------------------------------------------------
|
||||
* Liest data-top / data-left / data-width aus jedem Türchen (door, fluegel, openfield)
|
||||
* und positioniert sie pixelgenau auf dem sichtbaren Bild.
|
||||
*/
|
||||
|
||||
function positionAllDoors() {
|
||||
const cont = document.querySelector('.kalenderbild');
|
||||
const img = cont?.querySelector('img');
|
||||
@@ -13,7 +6,7 @@ function positionAllDoors() {
|
||||
const imgRect = img.getBoundingClientRect();
|
||||
const contRect = cont.getBoundingClientRect();
|
||||
|
||||
// === Normale Türen (.door)
|
||||
// Normale Türen
|
||||
document.querySelectorAll('.door').forEach(door => {
|
||||
const day = door.dataset.day;
|
||||
const topPct = parseFloat(door.dataset.top) || 0;
|
||||
@@ -38,25 +31,29 @@ function positionAllDoors() {
|
||||
}
|
||||
});
|
||||
|
||||
// === Flügel (.fluegel.left und .fluegel.right)
|
||||
document.querySelectorAll('.fluegel').forEach(fluegel => {
|
||||
const day = fluegel.dataset.day;
|
||||
const topPct = parseFloat(fluegel.dataset.top) || 0;
|
||||
const leftPct = parseFloat(fluegel.dataset.left) || 0;
|
||||
const widthPct = parseFloat(fluegel.dataset.width) || 6;
|
||||
// Flügel-Links/Rechts
|
||||
document.querySelectorAll('.fluegel').forEach(flg => {
|
||||
const day = flg.dataset.day;
|
||||
const side = flg.classList.contains('left') ? 'left' : 'right';
|
||||
const topPct = parseFloat(flg.dataset.top) || 0;
|
||||
const leftPct = parseFloat(flg.dataset.left) || 0;
|
||||
const widthPct = parseFloat(flg.dataset.width) || 12;
|
||||
|
||||
const w = imgRect.width * (widthPct / 100);
|
||||
const h = w * 2;
|
||||
const fullW = imgRect.width * (widthPct / 100);
|
||||
const halfW = fullW / 2;
|
||||
const fullH = fullW * 2;
|
||||
|
||||
fluegel.style.position = 'absolute';
|
||||
fluegel.style.width = `${w}px`;
|
||||
fluegel.style.height = `${h}px`;
|
||||
fluegel.style.top = `${imgRect.top - contRect.top + imgRect.height * (topPct / 100)}px`;
|
||||
fluegel.style.left = `${imgRect.width * (leftPct / 100) + (contRect.width - imgRect.width) / 2}px`;
|
||||
const baseLeft = imgRect.width * (leftPct / 100) + (contRect.width - imgRect.width) / 2;
|
||||
|
||||
flg.style.position = 'absolute';
|
||||
flg.style.width = `${halfW}px`;
|
||||
flg.style.height = `${fullH}px`;
|
||||
flg.style.top = `${imgRect.top - contRect.top + imgRect.height * (topPct / 100)}px`;
|
||||
flg.style.left = side === 'left' ? `${baseLeft}px` : `${baseLeft + halfW}px`;
|
||||
});
|
||||
|
||||
// === Openfields für Flügel
|
||||
document.querySelectorAll('.openfield').forEach(field => {
|
||||
// Offenes Feld bei Flügeltüren
|
||||
document.querySelectorAll('.openfield.double').forEach(field => {
|
||||
const day = field.dataset.day;
|
||||
const topPct = parseFloat(field.dataset.top) || 0;
|
||||
const leftPct = parseFloat(field.dataset.left) || 0;
|
||||
@@ -71,21 +68,9 @@ function positionAllDoors() {
|
||||
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`;
|
||||
});
|
||||
}
|
||||
|
||||
window.addEventListener('load', positionAllDoors);
|
||||
window.addEventListener('resize', positionAllDoors);
|
||||
window.addEventListener('orientationchange', () => {
|
||||
setTimeout(positionAllDoors, 300);
|
||||
});
|
||||
document.addEventListener('visibilitychange', () => {
|
||||
if (document.visibilityState === 'visible') {
|
||||
setTimeout(positionAllDoors, 200);
|
||||
}
|
||||
});
|
||||
|
||||
// === Zahlen für Flügeltüren (.door-number)
|
||||
document.querySelectorAll('.door-number').forEach(number => {
|
||||
// Zahlen mittig über beiden Flügeln
|
||||
document.querySelectorAll('.door-number').forEach(number => {
|
||||
const day = number.dataset.day;
|
||||
const topPct = parseFloat(number.dataset.top) || 0;
|
||||
const leftPct = parseFloat(number.dataset.left) || 0;
|
||||
@@ -99,9 +84,20 @@ document.querySelectorAll('.door-number').forEach(number => {
|
||||
number.style.height = `${h}px`;
|
||||
number.style.top = `${imgRect.top - contRect.top + imgRect.height * (topPct / 100)}px`;
|
||||
number.style.left = `${imgRect.width * (leftPct / 100) + (contRect.width - imgRect.width) / 2}px`;
|
||||
|
||||
number.style.display = 'flex';
|
||||
number.style.alignItems = 'center';
|
||||
number.style.justifyContent = 'center';
|
||||
number.style.pointerEvents = 'none';
|
||||
});
|
||||
}
|
||||
|
||||
window.addEventListener('load', positionAllDoors);
|
||||
window.addEventListener('resize', positionAllDoors);
|
||||
window.addEventListener('orientationchange', () => {
|
||||
setTimeout(positionAllDoors, 300);
|
||||
});
|
||||
document.addEventListener('visibilitychange', () => {
|
||||
if (document.visibilityState === 'visible') {
|
||||
setTimeout(positionAllDoors, 200);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user