Skip to content

An analog clock built with JavaScript and CSS for Wes Bos' JavaScript 30 course.

Notifications You must be signed in to change notification settings

gerhynes/js-and-css-clock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

An analog clockface built with JavaScript for Wes Bos' JavaScript 30 course.

Screenshot of JavaScript clock

Notes

CSS

Set the hands to start at 12 o clock using transform: rotate(90deg);.

By default elements rotate at their centre. Set the hands to rotate from their right end using transform-origin: 100%;.

Give the hands a realistic 'tick' using a cubic-bezier transition-timing function: transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1);.

JavaScript

Use a setInterval function to run the setDate() function every second.

Use new Date(); and now.getSeconds(); etc. to gte the current time.

Convert seconds, minutes and hours to degrees by dividing them by 60 or 12 and then multiplying the result by 360. Add 90 to offset the original move to 12 o clock.

The hands glitch when the second handreaches 12 as the second hand goes backwards to try to start again. Avoid this by using an if statement to set hand.style.transition = "none" if the seconds hand is at 90 degrees.

About

An analog clock built with JavaScript and CSS for Wes Bos' JavaScript 30 course.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published