diff --git a/_includes/head.html b/_includes/head.html index b9e83e83..c4dc6031 100644 --- a/_includes/head.html +++ b/_includes/head.html @@ -62,9 +62,7 @@ document.documentElement.style.setProperty('--vh', `${(w.height || w.innerHeight).toFixed(2) * 0.01}px`); // console.debug('set css variable --vh =', document.documentElement.style.getPropertyValue('--vh')); - console.log(w) - - w.addEventListener('resize', () => { + w.addEventListener('resize', debounce(() => { const _vh = ((w.height || w.innerHeight) * 0.01).toFixed(2); if (lastVH === _vh) { @@ -76,6 +74,14 @@ document.documentElement.style.setProperty('--vh', `${_vh}px`); window.scrollTo({top:0, left:0,behavior: 'instant'}); // console.debug('set css variable --vh =', _vh); - }) + }), timeout = 100) + + function debounce(func, timeout = 300) { + let timer; + return (...args) => { + clearTimeout(timer); + timer = setTimeout(() => { func.apply(this, args); }, timeout); + }; +} \ No newline at end of file