adventskalender/shared/js/position.js aktualisiert
This commit is contained in:
@@ -13,7 +13,7 @@ function positionAllDoors() {
|
|||||||
const imgRect = img.getBoundingClientRect();
|
const imgRect = img.getBoundingClientRect();
|
||||||
const contRect = cont.getBoundingClientRect();
|
const contRect = cont.getBoundingClientRect();
|
||||||
|
|
||||||
// alle Türchen positionieren
|
// === Einzel-Türen und Openfields ===
|
||||||
document.querySelectorAll('.door').forEach(door => {
|
document.querySelectorAll('.door').forEach(door => {
|
||||||
const day = door.dataset.day;
|
const day = door.dataset.day;
|
||||||
const topPct = parseFloat(door.dataset.top) || 0;
|
const topPct = parseFloat(door.dataset.top) || 0;
|
||||||
@@ -22,14 +22,12 @@ function positionAllDoors() {
|
|||||||
|
|
||||||
const w = imgRect.width * (widthPct / 100);
|
const w = imgRect.width * (widthPct / 100);
|
||||||
|
|
||||||
// Tür positionieren
|
|
||||||
door.style.position = 'absolute';
|
door.style.position = 'absolute';
|
||||||
door.style.width = w + 'px';
|
door.style.width = w + 'px';
|
||||||
door.style.height = w + 'px';
|
door.style.height = w + 'px';
|
||||||
door.style.top = (imgRect.top - contRect.top + imgRect.height * (topPct / 100)) + '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';
|
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}"]`);
|
const field = document.querySelector(`.openfield[data-day="${day}"]`);
|
||||||
if (field) {
|
if (field) {
|
||||||
field.style.position = 'absolute';
|
field.style.position = 'absolute';
|
||||||
@@ -39,19 +37,19 @@ function positionAllDoors() {
|
|||||||
field.style.left = door.style.left;
|
field.style.left = door.style.left;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
window.addEventListener('load', positionAllDoors);
|
// === Flügel (links & rechts) ===
|
||||||
window.addEventListener('resize', positionAllDoors);
|
document.querySelectorAll('.fluegel').forEach(flugel => {
|
||||||
|
const topPct = parseFloat(flugel.dataset.top) || 0;
|
||||||
|
const leftPct = parseFloat(flugel.dataset.left) || 0;
|
||||||
|
const widthPct = parseFloat(flugel.dataset.width) || 5;
|
||||||
|
|
||||||
// iOS / Mobile: neu berechnen bei Drehung oder Wake-up
|
const w = imgRect.width * (widthPct / 100);
|
||||||
window.addEventListener('orientationchange', () => {
|
|
||||||
setTimeout(positionAllDoors, 300); // kleiner Delay für Safari
|
|
||||||
});
|
|
||||||
|
|
||||||
// optional: neu positionieren, wenn die Seite wieder aktiv wird
|
flugel.style.position = 'absolute';
|
||||||
document.addEventListener('visibilitychange', () => {
|
flugel.style.width = w + 'px';
|
||||||
if (document.visibilityState === 'visible') {
|
flugel.style.height = w + 'px';
|
||||||
setTimeout(positionAllDoors, 200);
|
flugel.style.top = (imgRect.top - contRect.top + imgRect.height * (topPct / 100)) + 'px';
|
||||||
}
|
flugel.style.left = (imgRect.width * (leftPct / 100) + (contRect.width - imgRect.width) / 2) + 'px';
|
||||||
});
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user