Skip to content

Instantly share code, notes, and snippets.

@amadeuszblanik
Last active November 4, 2019 09:24
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 amadeuszblanik/28dd561c40977b729df82da67335b98f to your computer and use it in GitHub Desktop.
Save amadeuszblanik/28dd561c40977b729df82da67335b98f to your computer and use it in GitHub Desktop.
Vieport vh trick
// 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`);
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`);
})
}
}
height: calc(var(--vh, 1vh) * 100);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment