@@ -5,11 +5,14 @@ import HeaderLogo from "@components/header/header-logo.astro";
55import Search from " @components/Search.astro" ;
66
77import links from " @data/links.json" ;
8+
89---
910
1011<section
1112 id =" navbar"
1213 class =" fixed top-0 z-50 transition-transform duration-300 transform-gpu w-full"
14+ transition:name =" navbar"
15+ transition:animate =" fade"
1316>
1417 <div
1518 class =" container max-w-[1150px] mx-auto px-6 py-2 mt-1 lg:p-2 lg:mt-6 flex items-center justify-between relative z-40 bg-white/80 rounded-full backdrop-blur-md shadow-lg"
@@ -46,42 +49,48 @@ import links from "@data/links.json";
4649</section >
4750<Search />
4851
52+ <style >
53+ :root::view-transition-group(navbar) {
54+ z-index: 100;
55+ }
56+ </style >
4957<script >
50- document.addEventListener("DOMContentLoaded ", function() {
51- let prevScrollPos = window.scrollY || window. pageYOffset;
58+ document.addEventListener("astro:page-load ", () => {
59+ let prevScrollPos = window.pageYOffset;
5260 const navbar = document.getElementById("navbar");
53-
5461 if (!navbar) return;
5562
56- let ticking = false;
57-
58- window.addEventListener("scroll", function() {
59- if (!ticking) {
60- window.requestAnimationFrame(function() {
61- let currentScrollPos = window.scrollY || window.pageYOffset;
62-
63- if (prevScrollPos > currentScrollPos) {
64- navbar.style.transform = "translateY(0)";
65- } else {
66- navbar.style.transform = "translateY(-100%)";
67- }
68-
69- prevScrollPos = currentScrollPos;
70- ticking = false;
71- });
63+ let isFocused = false;
7264
73- ticking = true;
65+ window.addEventListener("scroll", () => {
66+ if (isFocused) return; // Don't hide navbar if focused
67+ let currentScrollPos = window.pageYOffset;
68+ if (prevScrollPos > currentScrollPos) {
69+ navbar.style.transform = "translateY(0)";
70+ } else {
71+ navbar.style.transform = "translateY(-100%)";
7472 }
73+ prevScrollPos = currentScrollPos;
7574 });
7675
77- navbar.addEventListener("focusin", function() {
76+ navbar.addEventListener("focusin", () => {
77+ isFocused = true;
7878 navbar.style.transform = "translateY(0)";
7979 });
8080
81- navbar.addEventListener("focusout", function() {
82- if ((window.scrollY || window.pageYOffset) > 100) {
81+ navbar.addEventListener("focusout", () => {
82+ isFocused = false;
83+ if (window.pageYOffset > 100) {
8384 navbar.style.transform = "translateY(-100%)";
8485 }
8586 });
8687});
88+
89+ document.addEventListener("astro:before-preparation", ()=>{
90+ window.scrollTo({ left: 0, top: 0, behavior: "instant" });
91+ });
92+
93+ document.addEventListener("astro:after-preparation", ()=>{
94+ window.scrollTo({ left: 0, top: 0, behavior: "instant" });
95+ });
8796</script >
0 commit comments