Last active
April 9, 2021 11:31
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:root { | |
--vh: 1vh; | |
} | |
.c-browserheight { | |
min-height: calc(100 * var(--vh)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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