"use client"; import { useEffect, useState } from "react"; import Link from "next/link"; import Image from "next/image"; const NAVBAR_HEIGHT = 100; // px — matches h-[6.25rem] const SCROLL_DURATION = 800; // ms function smoothScrollTo(targetY: number) { const startY = window.scrollY; const distance = targetY - startY; const startTime = performance.now(); function step(now: number) { const elapsed = now - startTime; const progress = Math.min(elapsed / SCROLL_DURATION, 1); // ease-in-out cubic const ease = progress < 0.5 ? 4 * progress ** 3 : 1 - (-2 * progress + 2) ** 3 / 2; window.scrollTo(0, startY + distance * ease); if (progress < 1) requestAnimationFrame(step); } requestAnimationFrame(step); } const navLinks = [ { label: "Werkzeuge", href: "#werkzeuge" }, { label: "Blog", href: "#blog" }, { label: "Über Björn", href: "#ueber-bjoern" }, { label: "Shop", href: "/shop" }, ]; const anchorIds = navLinks .filter((l) => l.href.startsWith("#")) .map((l) => l.href.slice(1)); export function Navbar() { const [scrolled, setScrolled] = useState(false); const [activeSection, setActiveSection] = useState(""); useEffect(() => { const onScroll = () => setScrolled(window.scrollY > 8); window.addEventListener("scroll", onScroll, { passive: true }); return () => window.removeEventListener("scroll", onScroll); }, []); useEffect(() => { const visible = new Set(); const updateActive = () => { for (const id of anchorIds) { if (visible.has(id)) { setActiveSection(id); return; } } setActiveSection(""); }; const observers = anchorIds.map((id) => { const el = document.getElementById(id); if (!el) return null; const obs = new IntersectionObserver( ([entry]) => { entry.isIntersecting ? visible.add(id) : visible.delete(id); updateActive(); }, { rootMargin: "-100px 0px -50% 0px" } ); obs.observe(el); return obs; }); return () => observers.forEach((o) => o?.disconnect()); }, []); return (
{/* Logo — smooth scroll to top */} { e.preventDefault(); smoothScrollTo(0); history.replaceState(null, "", "/"); }} > einfach produktiv {/* Nav links */} {/* CTA buttons */}
Newsletter 7-Tage-Challenge
); }