Skip to content

Instantly share code, notes, and snippets.

@mrtcmn
Created January 19, 2022 11:19
Show Gist options
  • Save mrtcmn/5236c947226e2daae71a53fb87214e54 to your computer and use it in GitHub Desktop.
Save mrtcmn/5236c947226e2daae71a53fb87214e54 to your computer and use it in GitHub Desktop.
Browser height detection
let vh = window.innerHeight * 0.01;
let vw = window.innerWidth * 0.01;
const setDimensions = (_vh, _vw) => {
const rs = _vh / _vw < 0.8 ? vh : vw;
document.documentElement.style.setProperty('--vh', `${_vh}px`);
document.documentElement.style.setProperty('--vw', `${_vw}px`);
document.documentElement.style.setProperty('--rs', `${rs}px`);
};
setDimensions(vh, vw);
window.addEventListener('resize', () => {
vh = window.innerHeight * 0.01;
vw = window.innerWidth * 0.01;
setDimensions(vh, vw);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment