test smarter viewport function
This commit is contained in:
parent
bc1b4ae4d6
commit
2ddd7ef7e4
1 changed files with 11 additions and 7 deletions
|
@ -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;
|
||||
}
|
||||
});
|
||||
*/
|
Loading…
Reference in a new issue