Created
April 12, 2023 09:48
-
-
Save ppeelman/d14ed1c341e6bc501583b16a047581c6 to your computer and use it in GitHub Desktop.
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 const setCorrectViewportHeightUnit = (interval = 1000): void => { | |
let currentHeight: number | null = null; | |
const update = () => { | |
if(currentHeight !== window.innerHeight) { | |
currentHeight = window.innerHeight | |
const vh = window.innerHeight * 0.01; | |
document.documentElement.style.setProperty('--vh', `${vh}px`); | |
} | |
} | |
setInterval(update, interval); | |
update(); | |
window.addEventListener('resize', throttle(update)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment