test smarter viewport function
This commit is contained in:
parent
bc1b4ae4d6
commit
2ddd7ef7e4
|
@ -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;
|
let vh = window.innerHeight * 0.01;
|
||||||
// Then we set the value in the --vh custom property to the root of the document
|
root.style.setProperty('--vh', `${vh}px`);
|
||||||
document.documentElement.style.setProperty('--vh', `${vh}px`);
|
this.lastHeight = window.innerHeight;
|
||||||
|
|
||||||
/*
|
|
||||||
// We listen to the resize event
|
// We listen to the resize event
|
||||||
window.addEventListener('resize', () => {
|
window.addEventListener('resize', () => {
|
||||||
// We execute the same script as before
|
// We execute the same script as before
|
||||||
let vh = window.innerHeight * 0.01;
|
if (
|
||||||
document.documentElement.style.setProperty('--vh', `${vh}px`);
|
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;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
*/
|
|
Loading…
Reference in a new issue