From 2ddd7ef7e4a707c932914019106861e8b25b4270 Mon Sep 17 00:00:00 2001 From: a Date: Wed, 22 Dec 2021 17:34:40 -0600 Subject: [PATCH] test smarter viewport function --- static/scripts/mobileViewportHeight.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/static/scripts/mobileViewportHeight.js b/static/scripts/mobileViewportHeight.js index 8022a5d..05db48b 100644 --- a/static/scripts/mobileViewportHeight.js +++ b/static/scripts/mobileViewportHeight.js @@ -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; + } }); -*/ \ No newline at end of file