diff --git a/_src/scroll.js b/_src/scroll.js index 56765a4e17d..69550bb9826 100644 --- a/_src/scroll.js +++ b/_src/scroll.js @@ -1,24 +1,28 @@ const fixNavHeight = () => { - const remainingVisibleTopBar = - document.querySelector('navigation').getBoundingClientRect().top - - window.scrollY; - if (remainingVisibleTopBar > 0) { - document.querySelector('navigation').style[ - 'height' - ] = `calc( 100vh - ${remainingVisibleTopBar}px)`; - } else { - document.querySelector('navigation').style['height'] = ''; + if (document.querySelector('navigation')) { + const remainingVisibleTopBar = + document.querySelector('navigation').getBoundingClientRect().top - + window.scrollY; + if (remainingVisibleTopBar > 0) { + document.querySelector('navigation').style[ + 'height' + ] = `calc( 100vh - ${remainingVisibleTopBar}px)`; + } else { + document.querySelector('navigation').style['height'] = ''; + } } }; document.addEventListener('DOMContentLoaded', () => { const element = document.querySelector('navigation .active'); - if (element.scrollIntoViewIfNeeded) { - element.scrollIntoViewIfNeeded(); - } else { - element.scrollIntoView(); + if (element) { + if (element.scrollIntoViewIfNeeded) { + element.scrollIntoViewIfNeeded(); + } else { + element.scrollIntoView(); + } + fixNavHeight(); } - fixNavHeight(); }); document.addEventListener('scroll', (event) => { window.requestAnimationFrame(fixNavHeight); -}); +}); \ No newline at end of file