feat(ui): synchronize mobile reflection speed with 1:1 parity and implement velocity-driven complete liquid wobble

This commit is contained in:
2026-11-03 16:02:18 +05:30
parent 5649e0f994
commit 81b781936c
2 changed files with 81 additions and 27 deletions
+6 -6
View File
@@ -128,7 +128,7 @@
z-index: 3; z-index: 3;
} }
/* Inverted Optical Liquid Glass Refraction Chamber with Pure Vertical Distortion */ /* Inverted Optical Liquid Glass Refraction Chamber with Dynamic Fluid Wobble */
.liquid-refraction-chamber { .liquid-refraction-chamber {
position: absolute; position: absolute;
inset: 0; inset: 0;
@@ -136,12 +136,12 @@
overflow: hidden; overflow: hidden;
pointer-events: none; pointer-events: none;
z-index: 1; z-index: 1;
/* Physical Optical Inversion & 3D Cylindrical Vertical Curvature */ /* Exact 1:1 speed matching inversion with 3D perspective */
transform: perspective(360px) rotateX(8deg) scaleY(-1.12) scaleX(1.02); transform: perspective(380px) rotateX(6deg) scaleY(-1);
transform-origin: center center; transform-origin: center center;
opacity: 0.75; opacity: 0.78;
mix-blend-mode: luminosity; mix-blend-mode: normal;
filter: url("#liquid-glass-vertical-refraction") blur(0.2px) contrast(124%) saturate(220%) brightness(1.05); filter: url("#liquid-glass-vertical-refraction") blur(0.2px) contrast(124%) saturate(210%) brightness(1.05);
contain: strict; contain: strict;
will-change: transform; will-change: transform;
} }
+75 -21
View File
@@ -19,7 +19,9 @@ export function Navbar({ config, currentLocale }: NavbarProps) {
const pathname = usePathname(); const pathname = usePathname();
const navRef = useRef<HTMLDivElement>(null); const navRef = useRef<HTMLDivElement>(null);
const mirrorRef = useRef<HTMLDivElement>(null); const mirrorRef = useRef<HTMLDivElement>(null);
const chamberRef = useRef<HTMLDivElement>(null);
const waveOffsetRef = useRef<SVGFEOffsetElement>(null); const waveOffsetRef = useRef<SVGFEOffsetElement>(null);
const dispMapRef = useRef<SVGFEDisplacementMapElement>(null);
useEffect(() => { useEffect(() => {
const handleScroll = () => { const handleScroll = () => {
@@ -29,23 +31,69 @@ export function Navbar({ config, currentLocale }: NavbarProps) {
return () => window.removeEventListener('scroll', handleScroll); return () => window.removeEventListener('scroll', handleScroll);
}, []); }, []);
// Optical Inverted Liquid Glass Refraction Pipeline (120 FPS on all devices) // Optical Inverted Liquid Glass Refraction Pipeline (Synchronized 120 FPS on all devices)
useEffect(() => { useEffect(() => {
let rafId: number; let rafId: number;
let lastY = 0;
let lastTime = performance.now();
let velocity = 0;
let wobblePhase = 0;
let navTop = 20;
let navLeft = 0;
// Cache navbar rect outside of scroll handler to avoid synchronous layout reflows on mobile
const measureNav = () => {
if (navRef.current) {
const rect = navRef.current.getBoundingClientRect();
navTop = rect.top;
navLeft = rect.left;
}
};
measureNav();
const updateMirror = () => { const updateMirror = () => {
if (!mirrorRef.current || !navRef.current) return; if (!mirrorRef.current) return;
const navRect = navRef.current.getBoundingClientRect(); // Direct hardware scroll position: 100% synchronized with native touch & desktop scroll
const lenis = (window as any).lenis; const scrollY = window.scrollY || window.pageYOffset || document.documentElement.scrollTop;
const scrollY = lenis && typeof lenis.scroll === 'number' ? lenis.scroll : window.scrollY; const now = performance.now();
const dt = Math.max(now - lastTime, 16);
const dist = Math.abs(scrollY - lastY);
const instantVelocity = (dist / dt) * 1000;
lastY = scrollY;
lastTime = now;
mirrorRef.current.style.left = `-${navRect.left}px`; // Smooth velocity interpolation
mirrorRef.current.style.transform = `translate3d(0, -${scrollY + navRect.top}px, 0)`; velocity += (instantVelocity - velocity) * 0.35;
// Dynamically ripple and displace the vertical liquid wave as text moves through the navbar // Exact 1:1 speed matching parity with hardware GPU translate3d
mirrorRef.current.style.left = `-${navLeft}px`;
mirrorRef.current.style.transform = `translate3d(0, -${scrollY + navTop}px, 0)`;
// Dynamic liquid wobble: 14 at rest, ramps up to 44 when scrolling (completely wobbles)
const currentWobble = Math.min(14 + velocity * 0.038, 44);
if (dispMapRef.current) {
dispMapRef.current.setAttribute('scale', currentWobble.toFixed(1));
}
// Wobbly phase oscillation
wobblePhase = (wobblePhase + dist * 0.4 + (velocity > 12 ? 2.2 : 0.4)) % 360;
if (waveOffsetRef.current) { if (waveOffsetRef.current) {
const offset = (scrollY * 0.45) % 200; const dy = Math.sin(wobblePhase * 0.05) * 26 + ((scrollY * 0.35) % 150);
waveOffsetRef.current.setAttribute('dy', offset.toString()); const dx = Math.cos(wobblePhase * 0.04) * (currentWobble * 0.35);
waveOffsetRef.current.setAttribute('dy', dy.toFixed(1));
waveOffsetRef.current.setAttribute('dx', dx.toFixed(1));
}
// 3D liquid fluid slosh & wobble on the chamber itself
if (chamberRef.current) {
const wobbleSkew = Math.sin(wobblePhase * 0.06) * Math.min(velocity * 0.007, 3.6);
chamberRef.current.style.transform = `perspective(380px) rotateX(6deg) scaleY(-1) skewX(${wobbleSkew.toFixed(2)}deg)`;
}
// Smooth deceleration loop
if (velocity > 1.2) {
cancelAnimationFrame(rafId);
rafId = requestAnimationFrame(updateMirror);
} }
}; };
@@ -63,6 +111,7 @@ export function Navbar({ config, currentLocale }: NavbarProps) {
(el as HTMLElement).style.pointerEvents = 'none'; (el as HTMLElement).style.pointerEvents = 'none';
}); });
mirrorRef.current.appendChild(clone); mirrorRef.current.appendChild(clone);
measureNav();
updateMirror(); updateMirror();
} }
}; };
@@ -77,18 +126,23 @@ export function Navbar({ config, currentLocale }: NavbarProps) {
const lenis = (window as any).lenis; const lenis = (window as any).lenis;
if (lenis && typeof lenis.on === 'function') { if (lenis && typeof lenis.on === 'function') {
lenis.on('scroll', updateMirror); lenis.on('scroll', onScroll);
} }
window.addEventListener('scroll', onScroll, { passive: true }); window.addEventListener('scroll', onScroll, { passive: true });
window.addEventListener('resize', onScroll, { passive: true }); window.addEventListener('touchmove', onScroll, { passive: true });
window.addEventListener('resize', () => {
measureNav();
onScroll();
}, { passive: true });
return () => { return () => {
clearTimeout(timer); clearTimeout(timer);
if (lenis && typeof lenis.off === 'function') { if (lenis && typeof lenis.off === 'function') {
lenis.off('scroll', updateMirror); lenis.off('scroll', onScroll);
} }
window.removeEventListener('scroll', onScroll); window.removeEventListener('scroll', onScroll);
window.removeEventListener('touchmove', onScroll);
window.removeEventListener('resize', onScroll); window.removeEventListener('resize', onScroll);
cancelAnimationFrame(rafId); cancelAnimationFrame(rafId);
}; };
@@ -107,16 +161,16 @@ export function Navbar({ config, currentLocale }: NavbarProps) {
return ( return (
<header className="fixed top-3 sm:top-5 left-0 right-0 z-50 px-3 sm:px-6 lg:px-8 pointer-events-none transition-all duration-300"> <header className="fixed top-3 sm:top-5 left-0 right-0 z-50 px-3 sm:px-6 lg:px-8 pointer-events-none transition-all duration-300">
{/* 1D Pure Vertical Optical Liquid Glass Refraction Filter (Single Dimension Y-axis for 120 FPS Speed) */} {/* Dynamic Liquid Glass Optical Wobble & Refraction Filter (120 FPS on all devices) */}
<svg className="absolute w-0 h-0 pointer-events-none overflow-hidden" aria-hidden="true" focusable="false"> <svg className="absolute w-0 h-0 pointer-events-none overflow-hidden" aria-hidden="true" focusable="false">
<defs> <defs>
<filter id="liquid-glass-vertical-refraction" x="0%" y="-10%" width="100%" height="120%" colorInterpolationFilters="sRGB"> <filter id="liquid-glass-vertical-refraction" x="-5%" y="-10%" width="110%" height="120%" colorInterpolationFilters="sRGB">
{/* Pure vertical fluid wave turbulence (X frequency = 0, Y frequency = 0.022) */} {/* Broad organic fluid liquid wave turbulence */}
<feTurbulence type="turbulence" baseFrequency="0 0.022" numOctaves="1" result="vertWave" /> <feTurbulence type="turbulence" baseFrequency="0.014 0.036" numOctaves="1" result="wobbleNoise" />
{/* Dynamic scroll-synchronized phase wave offset as content moves */} {/* Dynamic scroll-synchronized phase wave offset as content moves */}
<feOffset ref={waveOffsetRef} in="vertWave" dx="0" dy="0" result="movingWave" /> <feOffset ref={waveOffsetRef} in="wobbleNoise" dx="0" dy="0" result="movingWobble" />
{/* Active vertical optical refraction displacement along Y-axis */} {/* Active velocity-amplified liquid wobble displacement */}
<feDisplacementMap in="SourceGraphic" in2="movingWave" scale="18" xChannelSelector="R" yChannelSelector="R" result="displaced" /> <feDisplacementMap ref={dispMapRef} in="SourceGraphic" in2="movingWobble" scale="16" xChannelSelector="R" yChannelSelector="G" result="displaced" />
</filter> </filter>
</defs> </defs>
</svg> </svg>
@@ -130,7 +184,7 @@ export function Navbar({ config, currentLocale }: NavbarProps) {
}`} }`}
> >
{/* Optical Inverted Liquid Glass Refraction Chamber */} {/* Optical Inverted Liquid Glass Refraction Chamber */}
<div className="liquid-refraction-chamber" aria-hidden="true"> <div ref={chamberRef} className="liquid-refraction-chamber" aria-hidden="true">
<div ref={mirrorRef} className="liquid-refraction-mirror" /> <div ref={mirrorRef} className="liquid-refraction-mirror" />
<div className="liquid-caustic-refraction" /> <div className="liquid-caustic-refraction" />
</div> </div>