adventskalender/shared/js/position.js aktualisiert
This commit is contained in:
@@ -1,3 +1,10 @@
|
||||
/**
|
||||
* Bratonien Adventskalender – Türchen-Positionierung (2025)
|
||||
* ---------------------------------------------------------
|
||||
* Liest data-top / data-left / data-width aus jedem .fluegel und .openfield
|
||||
* und positioniert die Elemente exakt auf dem sichtbaren Bild.
|
||||
*/
|
||||
|
||||
function positionAllDoors() {
|
||||
const cont = document.querySelector('.kalenderbild');
|
||||
const img = cont?.querySelector('img');
|
||||
@@ -6,42 +13,43 @@ function positionAllDoors() {
|
||||
const imgRect = img.getBoundingClientRect();
|
||||
const contRect = cont.getBoundingClientRect();
|
||||
|
||||
// Türchen, Flügel und Felder positionieren
|
||||
document.querySelectorAll('[data-day]').forEach(el => {
|
||||
const day = el.dataset.day;
|
||||
const topPct = parseFloat(el.dataset.top) || 0;
|
||||
const leftPct = parseFloat(el.dataset.left) || 0;
|
||||
const widthPct = parseFloat(el.dataset.width) || 10;
|
||||
// Flügel (bei Doppeltüren) positionieren
|
||||
document.querySelectorAll('.fluegel').forEach(flg => {
|
||||
const day = flg.dataset.day;
|
||||
const topPct = parseFloat(flg.dataset.top) || 0;
|
||||
const leftPct = parseFloat(flg.dataset.left) || 0;
|
||||
const widthPct = parseFloat(flg.dataset.width) || 10;
|
||||
|
||||
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';
|
||||
const w = imgRect.width * (widthPct / 100);
|
||||
const h = w * 2; // Flügel doppelt so hoch wie breit
|
||||
|
||||
el.style.position = 'absolute';
|
||||
el.style.top = fullTop;
|
||||
el.style.left = fullLeft;
|
||||
flg.style.position = 'absolute';
|
||||
flg.style.width = w + 'px';
|
||||
flg.style.height = h + 'px';
|
||||
flg.style.top = (imgRect.top - contRect.top + imgRect.height * (topPct / 100)) + 'px';
|
||||
flg.style.left = (imgRect.width * (leftPct / 100) + (contRect.width - imgRect.width) / 2) + 'px';
|
||||
});
|
||||
|
||||
if (el.classList.contains('hinge-left') || el.classList.contains('hinge-right')) {
|
||||
el.style.width = fullWidth + 'px';
|
||||
el.style.height = fullWidth + 'px';
|
||||
// Openfields korrekt positionieren
|
||||
document.querySelectorAll('.openfield').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) || 10;
|
||||
|
||||
} else if (el.classList.contains('fluegel')) {
|
||||
el.style.width = fullWidth + 'px';
|
||||
el.style.height = (fullWidth * 2) + 'px';
|
||||
const w = imgRect.width * (widthPct / 100);
|
||||
|
||||
} else if (el.classList.contains('openfield')) {
|
||||
el.style.width = fullWidth + 'px';
|
||||
el.style.height = (fullWidth * 2) + 'px';
|
||||
const hasFluegel = document.querySelector(`.fluegel[data-day="${day}"]`);
|
||||
const h = hasFluegel ? w * 2 : w;
|
||||
|
||||
} else if (el.classList.contains('door-number')) {
|
||||
el.style.transform = 'translate(-50%, -50%)';
|
||||
el.style.left = '50%';
|
||||
el.style.top = '50%';
|
||||
}
|
||||
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';
|
||||
});
|
||||
}
|
||||
|
||||
// Events
|
||||
window.addEventListener('load', positionAllDoors);
|
||||
window.addEventListener('resize', positionAllDoors);
|
||||
window.addEventListener('orientationchange', () => {
|
||||
|
||||
Reference in New Issue
Block a user