Last active
October 3, 2019 21:24
-
-
Save unculturedswine/dd960202734eb9647afdd831b847382c to your computer and use it in GitHub Desktop.
Mobile Browser 100vh JS/CSS Fix
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
.selector { | |
height: 90vh; | |
height: calc(var(--vh, 1vh) * 100); | |
} |
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
// This helps us set the screen height to perfect 100%, and accounts for Safari grow/shrink on scroll | |
let vh = window.innerHeight * 0.01; | |
document.documentElement.style.setProperty('--vh', `${vh}px`); | |
window.addEventListener('resize', () => { | |
let vh = window.innerHeight * 0.01; | |
document.documentElement.style.setProperty('--vh', `${vh}px`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will allow you to set a full height/width element on mobile devices that will prevent an overflow scroll on mobile browsers because acting as intended is a bug for everyone else.