Use CSS custom property for cleaner random animation delay

- Move animation-delay to CSS using custom property --random-delay
- JavaScript still required to generate random value (CSS has no random functions)
- Cleaner separation between styling (CSS) and logic (JavaScript)
- Maintains same functionality with better organization
This commit is contained in:
Glen Maddern 2025-06-21 13:58:11 +10:00
commit b33bde6b0e
2 changed files with 2 additions and 1 deletions

View file

@ -105,7 +105,7 @@ const ChatApp: React.FC<ChatAppProps> = () => {
return (
<div
className="flex h-dvh w-screen overflow-clip bg-gradient-to-br from-pink-100 via-purple-50 to-indigo-100 animated-hue-bg"
style={{ animationDelay: `${animationDelay}s` }}
style={{ '--random-delay': `${animationDelay}s` } as React.CSSProperties}
>
<div className="flex flex-row flex-grow flex-1 overflow-hidden relative">
{/* Sidebar and Navbar components hidden but kept in codebase */}

View file

@ -13,4 +13,5 @@
.animated-hue-bg {
animation: hue-rotate 60s linear infinite;
animation-delay: var(--random-delay, 0s);
}