Ajuste le calcul du viewport mobile
This commit is contained in:
13
app.js
13
app.js
@@ -38,12 +38,16 @@ const MODES = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
syncViewportHeight();
|
syncViewportHeight();
|
||||||
|
window.addEventListener("load", syncViewportHeight);
|
||||||
window.addEventListener("resize", syncViewportHeight);
|
window.addEventListener("resize", syncViewportHeight);
|
||||||
|
window.addEventListener("scroll", syncViewportHeight, { passive: true });
|
||||||
window.addEventListener("pageshow", syncViewportHeight);
|
window.addEventListener("pageshow", syncViewportHeight);
|
||||||
window.addEventListener("orientationchange", syncViewportHeight);
|
window.addEventListener("orientationchange", syncViewportHeight);
|
||||||
window.visualViewport?.addEventListener("resize", syncViewportHeight);
|
window.visualViewport?.addEventListener("resize", syncViewportHeight);
|
||||||
window.visualViewport?.addEventListener("scroll", syncViewportHeight);
|
window.visualViewport?.addEventListener("scroll", syncViewportHeight);
|
||||||
window.setTimeout(syncViewportHeight, 0);
|
window.setTimeout(syncViewportHeight, 0);
|
||||||
|
window.setTimeout(syncViewportHeight, 150);
|
||||||
|
window.setTimeout(syncViewportHeight, 400);
|
||||||
window.requestAnimationFrame(() => {
|
window.requestAnimationFrame(() => {
|
||||||
window.requestAnimationFrame(syncViewportHeight);
|
window.requestAnimationFrame(syncViewportHeight);
|
||||||
});
|
});
|
||||||
@@ -91,7 +95,14 @@ switch (PAGE) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function syncViewportHeight() {
|
function syncViewportHeight() {
|
||||||
const viewportHeight = window.visualViewport?.height ?? window.innerHeight;
|
const visibleHeight = window.visualViewport?.height ?? window.innerHeight;
|
||||||
|
const viewportTopOffset = window.visualViewport?.offsetTop ?? 0;
|
||||||
|
const viewportHeight = Math.max(
|
||||||
|
visibleHeight + viewportTopOffset,
|
||||||
|
window.innerHeight,
|
||||||
|
document.documentElement.clientHeight,
|
||||||
|
);
|
||||||
|
|
||||||
document.documentElement.style.setProperty("--app-viewport-height", `${Math.round(viewportHeight)}px`);
|
document.documentElement.style.setProperty("--app-viewport-height", `${Math.round(viewportHeight)}px`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user