feat(ui): disable card tilting on mobile/tablet and add 1D vertical optical liquid glass distortion

This commit is contained in:
2026-11-03 15:51:34 +05:30
parent e14192d2a8
commit 52751143ac
3 changed files with 52 additions and 16 deletions
+12
View File
@@ -100,6 +100,18 @@ 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) */}
<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 turbulence: X frequency = 0, Y frequency = 0.032 */}
<feTurbulence type="turbulence" baseFrequency="0 0.032" numOctaves="1" result="vertWave" />
{/* Subtle vertical optical refraction displacement along Y-axis */}
<feDisplacementMap in="SourceGraphic" in2="vertWave" scale="7" xChannelSelector="R" yChannelSelector="R" result="displaced" />
</filter>
</defs>
</svg>
<div
ref={navRef}
onMouseMove={handleMouseMove}
+27 -4
View File
@@ -1,6 +1,6 @@
'use client';
import React, { useRef, useState, useCallback, MouseEvent } from 'react';
import React, { useRef, useState, useCallback, useEffect, MouseEvent } from 'react';
interface TiltCardProps {
children: React.ReactNode;
@@ -24,9 +24,25 @@ export function TiltCard({
background: '',
});
const [isHovered, setIsHovered] = useState<boolean>(false);
const [isTouchOrMobile, setIsTouchOrMobile] = useState<boolean>(true); // Default to true (safe for mobile/SSR)
useEffect(() => {
// Only enable 3D card tilt & glare on desktop screens with a precision mouse (>= 1024px)
const checkDevice = () => {
const isFinePointer = window.matchMedia('(hover: hover) and (pointer: fine)').matches;
const isSmallScreen = window.innerWidth < 1024;
const hasTouch = 'ontouchstart' in window || navigator.maxTouchPoints > 0;
setIsTouchOrMobile(!isFinePointer || isSmallScreen || hasTouch);
};
checkDevice();
window.addEventListener('resize', checkDevice, { passive: true });
return () => window.removeEventListener('resize', checkDevice);
}, []);
const handleMouseMove = useCallback(
(e: MouseEvent<HTMLDivElement>) => {
if (isTouchOrMobile) return;
const card = cardRef.current;
if (!card) return;
@@ -59,18 +75,25 @@ export function TiltCard({
});
}
},
[maxTilt, scale, showGlare]
[maxTilt, scale, showGlare, isTouchOrMobile]
);
const handleMouseEnter = useCallback(() => {
if (isTouchOrMobile) return;
setIsHovered(true);
}, []);
}, [isTouchOrMobile]);
const handleMouseLeave = useCallback(() => {
if (isTouchOrMobile) return;
setIsHovered(false);
setTransformStyle('perspective(1000px) rotateX(0deg) rotateY(0deg) scale3d(1, 1, 1)');
setGlareStyle((prev) => ({ ...prev, opacity: 0 }));
}, []);
}, [isTouchOrMobile]);
// On phone and tablet: zero tilt, zero glare, zero compositing overhead for ultra-smooth 120 FPS
if (isTouchOrMobile) {
return <div className={`relative ${className}`}>{children}</div>;
}
return (
<div