Skip to content

Instantly share code, notes, and snippets.

@MarioSo
Last active January 14, 2020 14:53
Show Gist options
  • Select an option

  • Save MarioSo/833eace64f225f66083ea689c16a526c to your computer and use it in GitHub Desktop.

Select an option

Save MarioSo/833eace64f225f66083ea689c16a526c to your computer and use it in GitHub Desktop.
Little helper mixin to make 100vh less painfull on mobile - more info here: https://css-tricks.com/the-trick-to-viewport-units-on-mobile/
@function vh($vh) {
@return calc(var(--vh, 1vh) * #{$vh});
}
@mixin vh($vh, $prop: height) {
#{$prop}: $vh * 1vh;
#{$prop}: vh($vh);
}
/// use it like this:
.fullscreen {
@include vh(100);
@include vh(100, 'width');
}
// add this to your JS
// don't forget to update on resize
const setViewportCSSVar = () => {
const vh = window.innerHeight * 0.01
document.documentElement.style.setProperty('--vh', `${vh}px`)
}
const onResize = () => {
setViewportCSSVar()
}
setViewportCSSVar()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment