Skip to content

Commit

Permalink
Merge pull request #797 from JosenRomero/feat/mobile-menu-animation
Browse files Browse the repository at this point in the history
add animation to mobile menu
  • Loading branch information
midudev authored May 13, 2024
2 parents 558fee3 + 0511eeb commit e18cbf1
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/components/Header.astro
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const isCombatIntern = normalizedPathName.startsWith("/combates/")
style="background:linear-gradient(to right, transparent 0%, white 50%, transparent 100%)"
/>
</div>
<nav class="flex w-full flex-col items-center gap-5">
<nav class="navContent flex w-full flex-col items-center gap-5">
<img
src="https://cdn.lavelada.dev/lvda.webp"
alt="lvda logo"
Expand Down Expand Up @@ -234,9 +234,14 @@ const isCombatIntern = normalizedPathName.startsWith("/combates/")
<script>
import { $ } from "@/lib/dom-selector"

function toggleMenu(nav: HTMLElement | null, menuMobileContent: HTMLElement | null) {
function toggleMenu(
nav: HTMLElement | null,
menuMobileContent: HTMLElement | null,
navContent: HTMLElement | null
) {
menuMobileContent?.classList.toggle("open")
nav?.classList.toggle("open")
navContent?.classList.toggle("animate-bounce-fade-in")
document.body.classList.toggle("overflow-hidden")
document.body.classList.toggle("lg:overflow-auto")
}
Expand All @@ -246,14 +251,17 @@ const isCombatIntern = normalizedPathName.startsWith("/combates/")
const menuButton = $("#menuButton")
const innerMenuButton = $("#innerMenuButton")
const menuMobileContext = $("#menuMobileContent")
const navContent = $(".navContent")

menuButton?.addEventListener("hamburgerButtonClicked", () => toggleMenu(nav, menuMobileContext))
menuButton?.addEventListener("hamburgerButtonClicked", () =>
toggleMenu(nav, menuMobileContext, navContent)
)
innerMenuButton?.addEventListener("hamburgerButtonClicked", () =>
toggleMenu(nav, menuMobileContext)
toggleMenu(nav, menuMobileContext, navContent)
)

if (menuMobileContext?.classList.contains("open")) {
toggleMenu(nav, menuMobileContext)
toggleMenu(nav, menuMobileContext, navContent)
}
})
</script>

0 comments on commit e18cbf1

Please sign in to comment.