feat(ui): synchronize mobile reflection speed with 1:1 parity and implement velocity-driven complete liquid wobble
This commit is contained in:
+6
-6
@@ -128,7 +128,7 @@
|
||||
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 {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
@@ -136,12 +136,12 @@
|
||||
overflow: hidden;
|
||||
pointer-events: none;
|
||||
z-index: 1;
|
||||
/* Physical Optical Inversion & 3D Cylindrical Vertical Curvature */
|
||||
transform: perspective(360px) rotateX(8deg) scaleY(-1.12) scaleX(1.02);
|
||||
/* Exact 1:1 speed matching inversion with 3D perspective */
|
||||
transform: perspective(380px) rotateX(6deg) scaleY(-1);
|
||||
transform-origin: center center;
|
||||
opacity: 0.75;
|
||||
mix-blend-mode: luminosity;
|
||||
filter: url("#liquid-glass-vertical-refraction") blur(0.2px) contrast(124%) saturate(220%) brightness(1.05);
|
||||
opacity: 0.78;
|
||||
mix-blend-mode: normal;
|
||||
filter: url("#liquid-glass-vertical-refraction") blur(0.2px) contrast(124%) saturate(210%) brightness(1.05);
|
||||
contain: strict;
|
||||
will-change: transform;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,9 @@ export function Navbar({ config, currentLocale }: NavbarProps) {
|
||||
const pathname = usePathname();
|
||||
const navRef = useRef<HTMLDivElement>(null);
|
||||
const mirrorRef = useRef<HTMLDivElement>(null);
|
||||
const chamberRef = useRef<HTMLDivElement>(null);
|
||||
const waveOffsetRef = useRef<SVGFEOffsetElement>(null);
|
||||
const dispMapRef = useRef<SVGFEDisplacementMapElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const handleScroll = () => {
|
||||
@@ -29,23 +31,69 @@ export function Navbar({ config, currentLocale }: NavbarProps) {
|
||||
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(() => {
|
||||
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 = () => {
|
||||
if (!mirrorRef.current || !navRef.current) return;
|
||||
const navRect = navRef.current.getBoundingClientRect();
|
||||
const lenis = (window as any).lenis;
|
||||
const scrollY = lenis && typeof lenis.scroll === 'number' ? lenis.scroll : window.scrollY;
|
||||
if (!mirrorRef.current) return;
|
||||
// Direct hardware scroll position: 100% synchronized with native touch & desktop scroll
|
||||
const scrollY = window.scrollY || window.pageYOffset || document.documentElement.scrollTop;
|
||||
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`;
|
||||
mirrorRef.current.style.transform = `translate3d(0, -${scrollY + navRect.top}px, 0)`;
|
||||
// Smooth velocity interpolation
|
||||
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) {
|
||||
const offset = (scrollY * 0.45) % 200;
|
||||
waveOffsetRef.current.setAttribute('dy', offset.toString());
|
||||
const dy = Math.sin(wobblePhase * 0.05) * 26 + ((scrollY * 0.35) % 150);
|
||||
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';
|
||||
});
|
||||
mirrorRef.current.appendChild(clone);
|
||||
measureNav();
|
||||
updateMirror();
|
||||
}
|
||||
};
|
||||
@@ -77,18 +126,23 @@ export function Navbar({ config, currentLocale }: NavbarProps) {
|
||||
|
||||
const lenis = (window as any).lenis;
|
||||
if (lenis && typeof lenis.on === 'function') {
|
||||
lenis.on('scroll', updateMirror);
|
||||
lenis.on('scroll', onScroll);
|
||||
}
|
||||
|
||||
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 () => {
|
||||
clearTimeout(timer);
|
||||
if (lenis && typeof lenis.off === 'function') {
|
||||
lenis.off('scroll', updateMirror);
|
||||
lenis.off('scroll', onScroll);
|
||||
}
|
||||
window.removeEventListener('scroll', onScroll);
|
||||
window.removeEventListener('touchmove', onScroll);
|
||||
window.removeEventListener('resize', onScroll);
|
||||
cancelAnimationFrame(rafId);
|
||||
};
|
||||
@@ -107,16 +161,16 @@ export function Navbar({ config, currentLocale }: NavbarProps) {
|
||||
|
||||
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">
|
||||
{/* 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">
|
||||
<defs>
|
||||
<filter id="liquid-glass-vertical-refraction" x="0%" y="-10%" width="100%" height="120%" colorInterpolationFilters="sRGB">
|
||||
{/* Pure vertical fluid wave turbulence (X frequency = 0, Y frequency = 0.022) */}
|
||||
<feTurbulence type="turbulence" baseFrequency="0 0.022" numOctaves="1" result="vertWave" />
|
||||
<filter id="liquid-glass-vertical-refraction" x="-5%" y="-10%" width="110%" height="120%" colorInterpolationFilters="sRGB">
|
||||
{/* Broad organic fluid liquid wave turbulence */}
|
||||
<feTurbulence type="turbulence" baseFrequency="0.014 0.036" numOctaves="1" result="wobbleNoise" />
|
||||
{/* Dynamic scroll-synchronized phase wave offset as content moves */}
|
||||
<feOffset ref={waveOffsetRef} in="vertWave" dx="0" dy="0" result="movingWave" />
|
||||
{/* Active vertical optical refraction displacement along Y-axis */}
|
||||
<feDisplacementMap in="SourceGraphic" in2="movingWave" scale="18" xChannelSelector="R" yChannelSelector="R" result="displaced" />
|
||||
<feOffset ref={waveOffsetRef} in="wobbleNoise" dx="0" dy="0" result="movingWobble" />
|
||||
{/* Active velocity-amplified liquid wobble displacement */}
|
||||
<feDisplacementMap ref={dispMapRef} in="SourceGraphic" in2="movingWobble" scale="16" xChannelSelector="R" yChannelSelector="G" result="displaced" />
|
||||
</filter>
|
||||
</defs>
|
||||
</svg>
|
||||
@@ -130,7 +184,7 @@ export function Navbar({ config, currentLocale }: NavbarProps) {
|
||||
}`}
|
||||
>
|
||||
{/* 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 className="liquid-caustic-refraction" />
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user