Skip to content

Commit f1a0a19

Browse files
committed
Draft nav blur gradient effect
1 parent e720eab commit f1a0a19

3 files changed

Lines changed: 57 additions & 12 deletions

File tree

layout/_partial/nav.ejs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
<div class="masked">
2+
<div order="1"></div>
3+
<div order="2"></div>
4+
<div order="3"></div>
5+
<div order="4"></div>
6+
<div order="5"></div>
7+
<div order="6"></div>
8+
</div>
19
<nav id="theme-nav">
210
<div class="inner">
311
<a class="title" href="<%= config.root %>"><%= theme.nav.title %></a>

source/css/nav.scss

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1+
@use 'sass:math';
2+
13
@mixin flex-center {
24
display: flex;
35
justify-content: center;
46
align-items: center;
57
}
68

79
nav {
8-
background-color: var(--color-background-secondary-translucent);
10+
// background-color: var(--color-background-secondary-translucent);
911
user-select: none;
1012
position: fixed;
1113
top: 0;
1214
left: 0;
1315
right: 0;
1416
z-index: 1000;
15-
backdrop-filter: var(--filter-blur);
17+
// backdrop-filter: var(--filter-blur);
1618
transition: height 0.4s cubic-bezier(0.86, 0, 0.07, 1);
1719

1820
.inner {
@@ -153,7 +155,7 @@ nav {
153155
}
154156
}
155157

156-
&.open {
158+
.nav-open & {
157159
height: var(--open-height);
158160

159161
.title {
@@ -195,3 +197,38 @@ nav {
195197
}
196198
}
197199
}
200+
201+
.masked > [order] {
202+
position: fixed;
203+
top: 0;
204+
left: 0;
205+
right: 0;
206+
// background-color: var(--color-background-secondary-translucent);
207+
background-color: rgba(0, 0, 0, 0.25);
208+
backdrop-filter: blur(10px);
209+
mask-image: linear-gradient(to bottom, #000, transparent);
210+
-webkit-mask-composite: destination-in;
211+
pointer-events: none;
212+
z-index: 1000;
213+
transition:
214+
height 0.6s cubic-bezier(0.86, 0, 0.07, 1),
215+
backdrop-filter 0.6s cubic-bezier(0.86, 0, 0.07, 1);
216+
217+
.nav-open & {
218+
backdrop-filter: blur(36px);
219+
}
220+
221+
--height: 100px;
222+
$base: 1.2;
223+
@for $i from 1 through 6 {
224+
&[order='#{$i}'] {
225+
height: calc(var(--height) / math.pow(($base), ($i - 1)));
226+
227+
@media (max-width: 600px) {
228+
.nav-open & {
229+
height: calc(var(--open-height) * 3 / math.pow(($base), ($i - 1)));
230+
}
231+
}
232+
}
233+
}
234+
}

source/js/main.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,34 @@
22
var navEl = document.getElementById('theme-nav')
33
navEl.addEventListener('click', e => {
44
if (window.innerWidth <= 600) {
5-
if (!navEl.classList.contains('open')) {
6-
navEl.style.setProperty(
5+
if (!document.body.classList.contains('nav-open')) {
6+
document.body.style.setProperty(
77
'--open-height',
88
48 +
99
document.querySelector('#theme-nav .nav-items').clientHeight +
1010
'px',
1111
)
1212
}
1313

14-
navEl.classList.toggle('open')
14+
document.body.classList.toggle('nav-open')
1515
} else {
16-
navEl.style.removeProperty('--open-height')
17-
navEl.classList.remove('open')
16+
document.body.style.removeProperty('--open-height')
17+
document.body.classList.remove('nav-open')
1818
}
1919
})
2020

2121
window.addEventListener('resize', () => {
22-
if (navEl.classList.contains('open')) {
23-
navEl.style.setProperty(
22+
if (document.body.classList.contains('nav-open')) {
23+
document.body.style.setProperty(
2424
'--open-height',
2525
48 +
2626
document.querySelector('#theme-nav .nav-items').clientHeight +
2727
'px',
2828
)
2929
}
3030
if (window.innerWidth > 600) {
31-
navEl.style.removeProperty('--open-height')
32-
navEl.classList.remove('open')
31+
document.body.style.removeProperty('--open-height')
32+
document.body.classList.remove('nav-open')
3333
}
3434
})
3535

0 commit comments

Comments
 (0)