adventskalender/shared/js/position.js aktualisiert
This commit is contained in:
@@ -6,91 +6,42 @@ function positionAllDoors() {
|
|||||||
const imgRect = img.getBoundingClientRect();
|
const imgRect = img.getBoundingClientRect();
|
||||||
const contRect = cont.getBoundingClientRect();
|
const contRect = cont.getBoundingClientRect();
|
||||||
|
|
||||||
// Normale Türen
|
// Türchen, Flügel und Felder positionieren
|
||||||
document.querySelectorAll('.door').forEach(door => {
|
document.querySelectorAll('[data-day]').forEach(el => {
|
||||||
const day = door.dataset.day;
|
const day = el.dataset.day;
|
||||||
const topPct = parseFloat(door.dataset.top) || 0;
|
const topPct = parseFloat(el.dataset.top) || 0;
|
||||||
const leftPct = parseFloat(door.dataset.left) || 0;
|
const leftPct = parseFloat(el.dataset.left) || 0;
|
||||||
const widthPct = parseFloat(door.dataset.width) || 10;
|
const widthPct = parseFloat(el.dataset.width) || 10;
|
||||||
|
|
||||||
const w = imgRect.width * (widthPct / 100);
|
const fullWidth = imgRect.width * (widthPct / 100);
|
||||||
|
const fullTop = (imgRect.top - contRect.top + imgRect.height * (topPct / 100)) + 'px';
|
||||||
|
const fullLeft = (imgRect.width * (leftPct / 100) + (contRect.width - imgRect.width) / 2) + 'px';
|
||||||
|
|
||||||
door.style.position = 'absolute';
|
el.style.position = 'absolute';
|
||||||
door.style.width = `${w}px`;
|
el.style.top = fullTop;
|
||||||
door.style.height = `${w}px`;
|
el.style.left = fullLeft;
|
||||||
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`;
|
|
||||||
|
|
||||||
const field = document.querySelector(`.openfield[data-day="${day}"]`);
|
if (el.classList.contains('hinge-left') || el.classList.contains('hinge-right')) {
|
||||||
if (field) {
|
el.style.width = fullWidth + 'px';
|
||||||
field.style.position = 'absolute';
|
el.style.height = fullWidth + 'px';
|
||||||
field.style.width = `${w}px`;
|
|
||||||
field.style.height = `${w}px`;
|
} else if (el.classList.contains('fluegel')) {
|
||||||
field.style.top = door.style.top;
|
el.style.width = fullWidth + 'px';
|
||||||
field.style.left = door.style.left;
|
el.style.height = (fullWidth * 2) + 'px';
|
||||||
|
|
||||||
|
} else if (el.classList.contains('openfield')) {
|
||||||
|
el.style.width = fullWidth + 'px';
|
||||||
|
el.style.height = (fullWidth * 2) + 'px';
|
||||||
|
|
||||||
|
} else if (el.classList.contains('door-number')) {
|
||||||
|
el.style.transform = 'translate(-50%, -50%)';
|
||||||
|
el.style.left = '50%';
|
||||||
|
el.style.top = '50%';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 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 fullW = imgRect.width * (widthPct / 100);
|
|
||||||
const halfW = fullW / 2;
|
|
||||||
const fullH = fullW * 2;
|
|
||||||
|
|
||||||
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`;
|
|
||||||
});
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
const widthPct = parseFloat(field.dataset.width) || 12;
|
|
||||||
|
|
||||||
const w = imgRect.width * (widthPct / 100);
|
|
||||||
const h = w * 2;
|
|
||||||
|
|
||||||
field.style.position = 'absolute';
|
|
||||||
field.style.width = `${w}px`;
|
|
||||||
field.style.height = `${h}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`;
|
|
||||||
});
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
const widthPct = parseFloat(number.dataset.width) || 12;
|
|
||||||
|
|
||||||
const w = imgRect.width * (widthPct / 100);
|
|
||||||
const h = w * 2;
|
|
||||||
|
|
||||||
number.style.position = 'absolute';
|
|
||||||
number.style.width = `${w}px`;
|
|
||||||
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';
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Events
|
||||||
window.addEventListener('load', positionAllDoors);
|
window.addEventListener('load', positionAllDoors);
|
||||||
window.addEventListener('resize', positionAllDoors);
|
window.addEventListener('resize', positionAllDoors);
|
||||||
window.addEventListener('orientationchange', () => {
|
window.addEventListener('orientationchange', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user