Skip to content

Instantly share code, notes, and snippets.

@markhowellsmead
Last active April 9, 2021 11:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markhowellsmead/5b5f2ac12020a4ae04b73ee5e0727058 to your computer and use it in GitHub Desktop.
Save markhowellsmead/5b5f2ac12020a4ae04b73ee5e0727058 to your computer and use it in GitHub Desktop.
Dynamically observe browser height (accounts for changes in e.g. iOS Safari on scroll)
:root {
--vh: 1vh;
}
.c-browserheight {
min-height: calc(100 * var(--vh));
}
const setBrowserHeightVar = () => {
document.documentElement.style.setProperty(
"--vh",
window.screen.height/100 + "px"
);
};
setBrowserHeightVar();
window.addEventListener("resize", setBrowserHeightVar);
window.addEventListener("orientationchange", setBrowserHeightVar);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment