Last active
January 14, 2020 14:53
-
-
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/
This file contains hidden or 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
| @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'); | |
| } |
This file contains hidden or 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
| // 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