调整时钟显示尺寸和布局

- 统一三种时钟样式的显示宽度为页面90%
- 增大翻页和滚动时钟的显示比例
- 优化响应式尺寸计算
- 调整页面布局使时钟占满宽度

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
ysm 2026-03-23 22:12:22 +08:00
parent ec06bdc29f
commit a431a5440f
3 changed files with 23 additions and 23 deletions

View File

@ -8,8 +8,9 @@
.app { .app {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: stretch;
min-height: 100vh; min-height: 100vh;
width: 100%;
padding-top: 40px; padding-top: 40px;
box-sizing: border-box; box-sizing: border-box;
} }
@ -25,6 +26,7 @@
z-index: 10; z-index: 10;
flex-shrink: 0; flex-shrink: 0;
margin-bottom: 60px; margin-bottom: 60px;
align-self: center;
} }
.clock-container { .clock-container {
@ -33,14 +35,12 @@
align-items: center; align-items: center;
flex: 1; flex: 1;
width: 100%; width: 100%;
padding: 0 20px;
box-sizing: border-box; box-sizing: border-box;
} }
/* Digital clock style (default) */ /* Digital clock style (default) */
.digital-clock { .digital-clock {
font-family: 'DSEG7', monospace; font-family: 'DSEG7', monospace;
font-size: clamp(48px, 15vw, 180px);
font-weight: bold; font-weight: bold;
color: #fff; color: #fff;
text-shadow: 0 0 20px rgba(255, 255, 255, 0.5); text-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
@ -72,10 +72,6 @@
/* Responsive adjustments */ /* Responsive adjustments */
@media (max-width: 768px) { @media (max-width: 768px) {
.digital-clock {
font-size: 12vw;
}
.style-selector { .style-selector {
gap: 8px; gap: 8px;
} }

View File

@ -5,9 +5,20 @@ import './App.css'
type ClockStyle = 'digital' | 'flip' | 'roll' type ClockStyle = 'digital' | 'flip' | 'roll'
function DigitalClock({ time }: { time: string }) { function DigitalClock({ time, size }: { time: string; size: number }) {
// Match width with flip/roll clocks
// Total flip/roll width ≈ 5.1 * (size / 1.6) because size is now scaled
// Actually size passed in is already the final size
// Flip: 6 * (size * 0.75) + 2 * (size * 0.3) = 4.5 * size + 0.6 * size = 5.1 * size
// Digital: 8 chars, each char ≈ fontSize * 0.6 wide in monospace = 4.8 * fontSize
// To match: 4.8 * fontSize = 5.1 * size => fontSize = size * 1.06
const fontSize = Math.floor(size * 1.06)
return ( return (
<div className="digital-clock"> <div
className="digital-clock"
style={{ fontSize: `${fontSize}px` }}
>
{time} {time}
</div> </div>
) )
@ -25,19 +36,14 @@ function App() {
return () => clearInterval(timer) return () => clearInterval(timer)
}, []) }, [])
// Responsive clock size // Responsive clock size - target 90% of page width
useEffect(() => { useEffect(() => {
const updateSize = () => { const updateSize = () => {
const width = window.innerWidth const width = window.innerWidth
if (width < 480) { // Direct calculation: target 90% width
setClockSize(Math.floor(width / 8)) const baseSize = (width * 0.9) / 5.1
} else if (width < 768) { const newSize = Math.floor(baseSize * 2.0) // Scale up more
setClockSize(Math.floor(width / 7)) setClockSize(Math.min(newSize, 320))
} else if (width < 1024) {
setClockSize(100)
} else {
setClockSize(120)
}
} }
updateSize() updateSize()
window.addEventListener('resize', updateSize) window.addEventListener('resize', updateSize)
@ -54,7 +60,7 @@ function App() {
return <RollClock time={timeString} size={clockSize} /> return <RollClock time={timeString} size={clockSize} />
case 'digital': case 'digital':
default: default:
return <DigitalClock time={timeString} /> return <DigitalClock time={timeString} size={clockSize} />
} }
} }

View File

@ -51,11 +51,9 @@
} }
#root { #root {
width: 1126px; width: 100%;
max-width: 100%;
margin: 0 auto; margin: 0 auto;
text-align: center; text-align: center;
border-inline: 1px solid var(--border);
min-height: 100svh; min-height: 100svh;
display: flex; display: flex;
flex-direction: column; flex-direction: column;