Skip to content

Commit

Permalink
fix: header
Browse files Browse the repository at this point in the history
  • Loading branch information
rxyhn committed Sep 26, 2024
1 parent 7384436 commit ff74bb5
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/components/Header.astro
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,24 @@ const subpath = pathname.match(/[^/]+/g);
</Container>
</header>

<script is:inline>
const header = document.getElementById("header");

<script>
function handleScroll() {
window.addEventListener("scroll", () => {
const header = document.getElementById("header");
if (header) {
if (window.scrollY > 0) {
header.classList.add("scrolled");
} else {
header.classList.remove("scrolled");
}
});
}
}

function setupScrollHandler() {
window.removeEventListener("scroll", handleScroll);
window.addEventListener("scroll", handleScroll);
handleScroll();
}
setupScrollHandler();

handleScroll();
document.addEventListener("astro:after-swap", handleScroll);
document.addEventListener("astro:after-swap", setupScrollHandler);
</script>

0 comments on commit ff74bb5

Please sign in to comment.