Last active
November 4, 2019 09:24
-
-
Save amadeuszblanik/28dd561c40977b729df82da67335b98f to your computer and use it in GitHub Desktop.
Vieport vh trick
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
// First we get the viewport height and we multiple it by 1% to get a value for a vh unit | |
const vh = window.innerHeight * 0.01; | |
// Then we set the value in the --vh custom property to the root of the document | |
document.documentElement.style.setProperty('--vh', `${vh}px`); |
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
export default () => { | |
if (typeof window === "object") { | |
document.documentElement.style.setProperty('--wh', `${window.innerHeight}px`); | |
window.addEventListener("resize", () => { | |
document.documentElement.style.setProperty('--wh', `${window.innerHeight}px`); | |
}) | |
} | |
} |
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
height: calc(var(--vh, 1vh) * 100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment