15 lines
601 B
TypeScript
15 lines
601 B
TypeScript
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();
|
|
}
|
|
};
|