Header blur and sticky
This commit is contained in:
parent
47b797f5f8
commit
cbc2587cc9
2 changed files with 46 additions and 1 deletions
|
|
@ -1,9 +1,21 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Avatar from './Avatar.svelte'
|
import Avatar from './Avatar.svelte'
|
||||||
import SegmentedController from './SegmentedController.svelte'
|
import SegmentedController from './SegmentedController.svelte'
|
||||||
|
|
||||||
|
let scrollY = $state(0)
|
||||||
|
let hasScrolled = $derived(scrollY > 10)
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
const handleScroll = () => {
|
||||||
|
scrollY = window.scrollY
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener('scroll', handleScroll)
|
||||||
|
return () => window.removeEventListener('scroll', handleScroll)
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<header class="site-header">
|
<header class="site-header {hasScrolled ? 'scrolled' : ''}">
|
||||||
<div class="header-content">
|
<div class="header-content">
|
||||||
<a href="/about" class="header-link" aria-label="@jedmund">
|
<a href="/about" class="header-link" aria-label="@jedmund">
|
||||||
<Avatar />
|
<Avatar />
|
||||||
|
|
@ -14,15 +26,43 @@
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
.site-header {
|
.site-header {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
z-index: 100;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
padding: $unit-5x 0;
|
padding: $unit-5x 0;
|
||||||
|
transition: padding 0.3s ease;
|
||||||
|
pointer-events: none;
|
||||||
|
|
||||||
|
&.scrolled {
|
||||||
|
padding: $unit-2x 0;
|
||||||
|
|
||||||
|
&::before {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
height: 120px;
|
||||||
|
background: linear-gradient(to bottom, rgba(0, 0, 0, 0.15), transparent);
|
||||||
|
backdrop-filter: blur(6px);
|
||||||
|
-webkit-backdrop-filter: blur(6px);
|
||||||
|
mask-image: linear-gradient(to bottom, black 0%, black 15%, transparent 90%);
|
||||||
|
-webkit-mask-image: linear-gradient(to bottom, black 0%, black 15%, transparent 90%);
|
||||||
|
pointer-events: none;
|
||||||
|
z-index: -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.header-content {
|
.header-content {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: $unit-3x;
|
gap: $unit-3x;
|
||||||
|
pointer-events: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.header-link {
|
.header-link {
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,11 @@ user-scalable=no"
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
main {
|
||||||
|
padding-top: calc(52px + #{$unit-5x * 2}); // Avatar height + header padding
|
||||||
|
min-height: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
@include breakpoint('phone') {
|
@include breakpoint('phone') {
|
||||||
:global(html) {
|
:global(html) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue