|
export function updateBackground(): void { |
|
const hour = new Date().getHours(); |
|
const background = document.getElementById('bg') as HTMLElement | null; |
|
|
|
if (!background) { |
|
console.warn("Background element not found, will retry later."); |
|
setTimeout(updateBackground, 500); |
|
return; |
|
} |
|
|
|
let color1, color2, color3, color4; |
|
let cloudStyle = ''; |
|
|
|
if (hour >= 5 && hour < 7) { |
|
|
|
color1 = 'rgba(255, 140, 0, 0.6)'; |
|
color2 = 'rgba(135, 206, 250, 0.6)'; |
|
color3 = '#F0E68C'; |
|
} else if (hour >= 7 && hour < 16) { |
|
|
|
color1 = 'rgba(135, 206, 250, 0.6)'; |
|
color2 = 'rgba(255, 255, 255, 0.6)'; |
|
color3 = '#87CEEB'; |
|
cloudStyle = ', radial-gradient(circle at 10% 30%, rgba(255, 255, 255, 0.8), transparent 80%), radial-gradient(circle at 90% 40%, rgba(255, 255, 255, 0.8), transparent 80%)'; |
|
} else if (hour >= 16 && hour < 20) { |
|
|
|
color1 = 'rgba(250, 128, 114, 0.6)'; |
|
color2 = 'rgba(100, 149, 237, 0.6)'; |
|
color3 = '#B0C4DE'; |
|
} else { |
|
|
|
color1 = 'rgba(0, 0, 0, 1)'; |
|
color2 = 'rgba(0, 0, 0, 1)'; |
|
color3 = '#000000'; |
|
} |
|
|
|
|
|
if (hour >= 6 && hour < 18) { |
|
|
|
color4 = 'rgba(255, 255, 255, 0.2)'; |
|
} else { |
|
|
|
color4 = 'rgba(0, 0, 0, 0.1)'; |
|
} |
|
|
|
|
|
background.style.backgroundImage = |
|
`radial-gradient(circle at 50% 20%, ${color1}, transparent 90%), |
|
radial-gradient(circle at 50% 80%, ${color2}, transparent 90%)${cloudStyle}`; |
|
background.style.backgroundColor = color3; |
|
|
|
|
|
if (cloudStyle) { |
|
background.style.animation = 'moveClouds 60s linear infinite'; |
|
} else { |
|
background.style.animation = 'none'; |
|
} |
|
|
|
const beforeElement: any = document.querySelector('.background::before'); |
|
const afterElement: any = document.querySelector('.background::after'); |
|
|
|
if (beforeElement && afterElement) { |
|
beforeElement.style.backgroundImage = `radial-gradient(closest-side, ${color4}, transparent)`; |
|
afterElement.style.backgroundImage = `radial-gradient(closest-side, ${color4}, transparent)`; |
|
} |
|
} |