test smarter viewport function

This commit is contained in:
a 2021-12-22 17:34:40 -06:00
parent bc1b4ae4d6
commit 2ddd7ef7e4

View file

@ -1,13 +1,17 @@
// First we get the viewport height and we multiple it by 1% to get a value for a vh unit
var root = document.documentElement;
let vh = window.innerHeight * 0.01;
// Then we set the value in the --vh custom property to the root of the document
document.documentElement.style.setProperty('--vh', `${vh}px`);
root.style.setProperty('--vh', `${vh}px`);
this.lastHeight = window.innerHeight;
/*
// We listen to the resize event
window.addEventListener('resize', () => {
// We execute the same script as before
let vh = window.innerHeight * 0.01;
document.documentElement.style.setProperty('--vh', `${vh}px`);
if (
window.innerWidth > window.innerHeight ||
Math.abs(this.lastHeight - window.innerHeight) > 100
) {
let vh = window.innerHeight * 0.01;
root.style.setProperty('--vh', `${vh}px`);
this.lastHeight = window.innerHeight;
}
});
*/