capybara/frontend/src/responsive.ts

16 lines
601 B
TypeScript
Raw Normal View History

2024-09-13 22:19:09 +03:00
export const initViewportExtents = () => {
const root = document.querySelector<HTMLElement>(':root');
if (CSS.supports("(width: 1dvw)") && root) {
root.style.setProperty("--viewportWidth", "100dvw");
root.style.setProperty("--viewportHeight", "100dvh");
} else if (root) {
const updateUnits = () => {
root.style.setProperty("--viewportWidth", `${window.innerWidth}px`);
root.style.setProperty("--viewportHeight", `${window.innerHeight}px`);
};
window.addEventListener("resize", updateUnits);
updateUnits();
}
};