|
1 | 1 | <script lang="ts"> |
| 2 | + import { resolve } from '$app/paths'; |
2 | 3 | import { page } from '$app/state'; |
3 | 4 |
|
4 | 5 | // verify the current url pathname equals the menu href |
5 | 6 | let isCurrentPage = (path: string): boolean => page.url.pathname.split('/')[1] === path; |
6 | 7 |
|
7 | 8 | // check the scroll state to decrease the header padding |
8 | 9 | let scrollY: number = $state(0); |
9 | | - let scrollOffsetClass = (): string | null => (scrollY > 1 ? 'scrolled' : null); |
| 10 | + let isScrolled = $derived(scrollY > 1); |
10 | 11 |
|
11 | 12 | // toggle mobile menu state |
12 | 13 | let mobileMenuActive: boolean = $state(false); |
|
28 | 29 |
|
29 | 30 | <svelte:window bind:scrollY bind:innerWidth /> |
30 | 31 |
|
31 | | -<header class={scrollOffsetClass()}> |
| 32 | +<header class:scrolled={isScrolled}> |
32 | 33 | <div class="logo"> |
33 | | - <a href="/"> |
| 34 | + <a href={resolve('/')}> |
34 | 35 | <img alt="tukkr logo" height="42" width="42" src="/logo.svg" /> |
35 | 36 | </a> |
36 | 37 | </div> |
|
42 | 43 | </svg> |
43 | 44 | </button> |
44 | 45 | <nav aria-label="Main menu" class:active={mobileMenuActive} id="main-menu"> |
45 | | - <a class:active={isCurrentPage('')} href="/">Home</a> |
46 | | - <a class:active={isCurrentPage('about')} href="/about">About</a> |
47 | | - <a class:active={isCurrentPage('snippets')} href="/snippets">Snippets</a> |
48 | | - <a class:active={isCurrentPage('contact')} href="/contact">Contact</a> |
| 46 | + <a class:active={isCurrentPage('')} href={resolve('/')}>Home</a> |
| 47 | + <a class:active={isCurrentPage('about')} href={resolve('/about')}>About</a> |
| 48 | + <a class:active={isCurrentPage('snippets')} href={resolve('/snippets')}>Snippets</a> |
| 49 | + <a class:active={isCurrentPage('contact')} href={resolve('/contact')}>Contact</a> |
49 | 50 | </nav> |
50 | 51 | </header> |
51 | 52 |
|
|
61 | 62 | will-change: padding; |
62 | 63 | padding: 1.8rem 2rem; |
63 | 64 | background-color: rgba(255, 255, 255, 0.94); |
64 | | - transition: padding 0.2s ease-in-out; |
| 65 | + transition: padding 0.2s ease-in-out !important; |
65 | 66 | z-index: 999; |
66 | 67 |
|
67 | 68 | // change padding if window is scrolled |
|
86 | 87 | will-change: transform, stroke-dashoffset; |
87 | 88 | transition: |
88 | 89 | transform $animation-duration-slow ease-in-out, |
89 | | - stroke-dashoffset $animation-duration-slow ease-in-out; |
| 90 | + stroke-dashoffset $animation-duration-slow ease-in-out !important; |
90 | 91 |
|
91 | 92 | path { |
92 | 93 | fill: none; |
|
128 | 129 | margin-top: 0; |
129 | 130 | transition: |
130 | 131 | height $animation-duration-slow ease-in-out, |
131 | | - margin-top $animation-duration-slow ease-in-out; |
| 132 | + margin-top $animation-duration-slow ease-in-out !important; |
132 | 133 |
|
133 | 134 | &.active { |
134 | 135 | // note: height must be a fixed value for transition to work properly |
|
144 | 145 | margin-top: 0 !important; |
145 | 146 |
|
146 | 147 | // disable transition to prevent weird rescaling animations |
147 | | - transition: none; |
| 148 | + transition: none !important; |
148 | 149 | } |
149 | 150 |
|
150 | 151 | a { |
|
0 commit comments