diff --git a/apps/landing/CLAUDE.md b/apps/landing/CLAUDE.md index ac15532f..f65e43ec 100644 --- a/apps/landing/CLAUDE.md +++ b/apps/landing/CLAUDE.md @@ -14,6 +14,8 @@ The landing design lives in `design/landing.pen` (frame `Landing v0.1`, plus the Next.js 16 App Router + Tailwind 4, same pinned versions as `apps/fe`. Bun 1.3.9 (`npx -y bun@1.3.9 …` works without a global install). +Smooth scrolling: `lenis` 1.3.27 (Axel, 13 Nov), in `components/SmoothScroll.tsx`. It drives the page's own scroll (no wrapper), runs on GSAP's ticker and calls `ScrollTrigger.update` on every scroll, so the pins and the scrubbed approvals scene stay in step (checked: the scene at the same scrollY looks the same with and without it, mean pixel difference 0.2 of 255). Touch keeps the device's own scrolling; reduced motion gets no Lenis. It is stopped until the page loader lifts (`hn:reveal`). It sits on `window.__lenis`, so code that jumps (`PageLoader`'s in-page links, `OverlayScrollbar`'s drag) calls `lenis.scrollTo(y, { immediate: true })` instead of `window.scrollTo`, or Lenis would glide on to where it was heading. `anchors` is off: `PageLoader` handles in-page links. + ```sh bun install bun run dev # http://localhost:3100 (apps/fe keeps 3000) diff --git a/apps/landing/app/layout.tsx b/apps/landing/app/layout.tsx index d1a9c950..2a1a9741 100644 --- a/apps/landing/app/layout.tsx +++ b/apps/landing/app/layout.tsx @@ -3,6 +3,7 @@ import { Geist } from "next/font/google"; import "./globals.css"; import { OverlayScrollbar } from "@/components/OverlayScrollbar"; import { PageLoader } from "@/components/PageLoader"; +import { SmoothScroll } from "@/components/SmoothScroll"; const geist = Geist({ subsets: ["latin"], variable: "--font-geist" }); @@ -32,6 +33,7 @@ export default function RootLayout({ children }: { children: React.ReactNode }) + {children} diff --git a/apps/landing/bun.lock b/apps/landing/bun.lock index 4efb7097..68e7197e 100644 --- a/apps/landing/bun.lock +++ b/apps/landing/bun.lock @@ -6,6 +6,7 @@ "name": "@hellonear/landing", "dependencies": { "gsap": "3.15.1", + "lenis": "1.3.27", "next": "16.4.4", "react": "19.3.1", "react-dom": "19.3.1", @@ -177,6 +178,8 @@ "jiti": ["jiti@2.7.0", "", { "bin": { "jiti": "lib/jiti-cli.mjs" } }, "sha512-AC/7JofJvZGrrneWNaEnJeOLUx+JlGt7tNa0wZiRPT4MY1wmfKjt2+6O2p2uz2+skll8OZZmJMNqeke7kKbNgQ=="], + "lenis": ["lenis@1.3.27", "", { "peerDependencies": { "@nuxt/kit": ">=3.0.0", "react": ">=17.0.0", "vue": ">=3.0.0" }, "optionalPeers": ["@nuxt/kit", "react", "vue"] }, "sha512-QIHNH4LIfWyLfgH/5K0aTGZgyFJJ7GfHNcaH/AIgyKjb8gstLh5siNGvrVqz1w5ClLXzOvllBVk7vby8JzUVPQ=="], + "lightningcss": ["lightningcss@1.33.0", "", { "dependencies": { "detect-libc": "^2.0.3" }, "optionalDependencies": { "lightningcss-android-arm64": "1.33.0", "lightningcss-darwin-arm64": "1.33.0", "lightningcss-darwin-x64": "1.33.0", "lightningcss-freebsd-x64": "1.33.0", "lightningcss-linux-arm-gnueabihf": "1.33.0", "lightningcss-linux-arm64-gnu": "1.33.0", "lightningcss-linux-arm64-musl": "1.33.0", "lightningcss-linux-x64-gnu": "1.33.0", "lightningcss-linux-x64-musl": "1.33.0", "lightningcss-win32-arm64-msvc": "1.33.0", "lightningcss-win32-x64-msvc": "1.33.0" } }, "sha512-WkUDrojuJs0xkgGf2udWxa3yGBRxPtxUkB79i6aCZLRgc7PM8fZe9TosfPDcvEpQZbuFASnHYmRLBLUbmLOIIA=="], "lightningcss-android-arm64": ["lightningcss-android-arm64@1.33.0", "", { "os": "android", "cpu": "arm64" }, "sha512-gEpRTalKdosp4Bb8qWtc2iOgE5SeIHlpS1up9bFq2wAyYhl1UdTObYiHe98zEM9SQvSoqQZ1IQD0JNpg3Ml5pg=="], diff --git a/apps/landing/components/OverlayScrollbar.tsx b/apps/landing/components/OverlayScrollbar.tsx index 00115974..a0d16638 100644 --- a/apps/landing/components/OverlayScrollbar.tsx +++ b/apps/landing/components/OverlayScrollbar.tsx @@ -74,9 +74,11 @@ export function OverlayScrollbar() { const total = document.documentElement.scrollHeight; const travel = view - el.offsetHeight; if (travel <= 0) return; - // Thumb pixels to page pixels; "instant", since the page scrolls smoothly by default. + // Thumb pixels to page pixels, at once: through Lenis when it runs (SmoothScroll), else "instant". const top = d.startScroll + ((e.clientY - d.startY) / travel) * (total - view); - window.scrollTo({ top, behavior: "instant" }); + const lenis = (window as unknown as { __lenis?: { scrollTo: (y: number, o: { immediate: boolean }) => void } }).__lenis; + if (lenis) lenis.scrollTo(top, { immediate: true }); + else window.scrollTo({ top, behavior: "instant" }); }; const onUp = () => { drag.current = null; diff --git a/apps/landing/components/PageLoader.tsx b/apps/landing/components/PageLoader.tsx index 59435e7d..d720b9ef 100644 --- a/apps/landing/components/PageLoader.tsx +++ b/apps/landing/components/PageLoader.tsx @@ -117,7 +117,10 @@ export function PageLoader() { requestAnimationFrame(() => requestAnimationFrame(() => setPhase("cover"))); setTimeout(() => { const y = targetY(hash) ?? 0; - window.scrollTo({ top: y, behavior: "instant" as ScrollBehavior }); + // Through Lenis when it runs (SmoothScroll), or it would glide on to where it was heading. + const lenis = (window as unknown as { __lenis?: { scrollTo: (y: number, o: { immediate: boolean; force: boolean }) => void } }).__lenis; + if (lenis) lenis.scrollTo(y, { immediate: true, force: true }); + else window.scrollTo({ top: y, behavior: "instant" as ScrollBehavior }); // No "#…" in the address (Ancung, 13 Nov): the link still works, the bar stays hellonear.xyz. history.replaceState(null, "", location.pathname + location.search); // let the scroll-driven scenes settle and the images there decode, then lift diff --git a/apps/landing/components/SmoothScroll.tsx b/apps/landing/components/SmoothScroll.tsx new file mode 100644 index 00000000..f7ba6d77 --- /dev/null +++ b/apps/landing/components/SmoothScroll.tsx @@ -0,0 +1,38 @@ +"use client"; + +import { useEffect } from "react"; +import gsap from "gsap"; +import { ScrollTrigger } from "gsap/ScrollTrigger"; +import Lenis from "lenis"; +import "lenis/dist/lenis.css"; + +gsap.registerPlugin(ScrollTrigger); + +// Smooth wheel scrolling with Lenis (Axel, 13 Nov). It drives the page's own scroll (no wrapper), so +// position: sticky, the GSAP pins and every scrollY reader keep working. Lenis runs on GSAP's ticker +// and tells ScrollTrigger on every scroll, so the scrubbed approvals scene and the pins move in step +// with it. Touch keeps the device's own scrolling (Lenis' default). Reduced motion: no Lenis. +// Held still while the page loader covers the page, as the loader locks the scroll. +export function SmoothScroll() { + useEffect(() => { + if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return; + const lenis = new Lenis({ autoRaf: false, anchors: false }); + (window as unknown as { __lenis?: Lenis }).__lenis = lenis; + lenis.on("scroll", ScrollTrigger.update); + const tick = (time: number) => lenis.raf(time * 1000); + gsap.ticker.add(tick); + gsap.ticker.lagSmoothing(0); + + const revealed = (window as unknown as { __hnRevealed?: boolean }).__hnRevealed; + if (!revealed) lenis.stop(); + const start = () => lenis.start(); + window.addEventListener("hn:reveal", start); + return () => { + window.removeEventListener("hn:reveal", start); + gsap.ticker.remove(tick); + lenis.destroy(); + delete (window as unknown as { __lenis?: Lenis }).__lenis; + }; + }, []); + return null; +} diff --git a/apps/landing/package.json b/apps/landing/package.json index a354b2c6..8575ddc3 100644 --- a/apps/landing/package.json +++ b/apps/landing/package.json @@ -13,6 +13,7 @@ }, "dependencies": { "gsap": "3.15.1", + "lenis": "1.3.27", "next": "16.4.4", "react": "19.3.1", "react-dom": "19.3.1",