Skip to content

Instantly share code, notes, and snippets.

@ppeelman
Created April 12, 2023 09:48
Show Gist options
  • Save ppeelman/d14ed1c341e6bc501583b16a047581c6 to your computer and use it in GitHub Desktop.
Save ppeelman/d14ed1c341e6bc501583b16a047581c6 to your computer and use it in GitHub Desktop.
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