diff --git a/docusaurus.config.js b/docusaurus.config.js index fbc27eba..61267a6d 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -26,7 +26,7 @@ const config = { }, }, }, - clientModules: [require.resolve('./src/pages/components/NavbarScroll.jsx')], + clientModules: [require.resolve('./src/NavbarScroll.js')], presets: [ [ 'classic', diff --git a/src/pages/components/NavbarScroll.jsx b/src/NavbarScroll.js similarity index 64% rename from src/pages/components/NavbarScroll.jsx rename to src/NavbarScroll.js index 904429aa..f79698ff 100644 --- a/src/pages/components/NavbarScroll.jsx +++ b/src/NavbarScroll.js @@ -1,4 +1,6 @@ -document.addEventListener('DOMContentLoaded', function () { +import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment'; + +if (ExecutionEnvironment.canUseDOM) { function changeNavbarScroll() { const navbarElement = document.querySelector('.navbar'); if (navbarElement) { @@ -10,7 +12,5 @@ document.addEventListener('DOMContentLoaded', function () { } } - document.addEventListener('scroll', changeNavbarScroll); - - changeNavbarScroll(); -}); + window.addEventListener('scroll', changeNavbarScroll); +}