fix: smooth continuous second-hand motion with millisecond precision …#219
fix: smooth continuous second-hand motion with millisecond precision …#219dfleper wants to merge 1 commit into
Conversation
…and higher update rate
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe PR refines the analog clock's second-hand animation behavior by introducing millisecond-precision timing, eliminating backward rotation jumps at minute boundaries through continuous ChangesAnalog Clock Timing and Animation
🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
This PR fixes the analog clock second-hand behavior reported in #102.
The second hand now moves continuously (instead of stepping once per second), uses millisecond precision, and keeps forward continuity when crossing minute boundaries (
59.xs -> 0.xs) to avoid backward visual jumps.Root cause
Changes made
scripts/clock.jsonly.currentMillisecondsand compute:newSecondRotation = (currentSeconds + (currentMilliseconds / 1000)) * 6transform 0.05s linear500msto50ms.updateHandRotationflow (no refactor).Why this is minimal and safe
Validation
node --check scripts/clock.js✅59.xs -> 0.xs); it should continue forward without visual backward jump.Notes
Summary
This PR fixes the analog clock's second-hand animation to display smooth continuous motion with proper minute-boundary handling.
Changes
scripts/clock.js
Second-hand millisecond precision: Updated second-hand rotation calculation from using only
secondsto(seconds + milliseconds/1000) * 6, enabling sub-second granularity and smoother visual motion.Increased update frequency: Changed the analog clock refresh interval from 500ms to 50ms via
setInterval(updateanalogclock, 50), reducing perceived stepping artifacts.Smooth second-hand animation: Applied a short linear CSS transition (
transform 0.05s linear) to the second hand, replacing the previous approach and creating fluid motion between updates.Cumulative forward rotation logic: Implemented logic to compute continuous second-hand rotation across minute boundaries by tracking cumulative rotation (
cumulativeSecondRotation) and detecting when the computed angle would represent a backward motion, then adding 360° to preserve forward continuity (preventing a visual backward jump at 59.x → 0.x seconds).Preserved minute/hour hand behavior: The minute and hour hands continue to use the existing
updateHandRotation()function with its 1-second ease transition, ensuring no change to their animation behavior.Details
The second hand now directly updates its cumulative rotation state within
updateanalogclock()rather than relying on the reset-condition logic used for minute/hour hands. The formulacurrentSecondTurn + newSecondRotationwith forward-continuity checks ensures the second hand rotates forward across all minute rollovers.No changes to HTML, CSS, layout, dependencies, or API surface. The fix is confined to animation logic within a single file.
Lines changed: +15/-6