Build A Clock With JavaScript




One of the best projects for learning CSS and JavaScript is an analog clock. Creating an analog clock teaches you how to use absolute position and transform in many different ways. It also forces you to learn how to modify your CSS with JavaScript. Lastly, it is a beginner friendly project which makes it perfect for anyone.

In this video we will be covering CSS position, and transform extensively. We will also use CSS variables to make the JavaScript integration much easier. By the end of this quick video you will have a fully functional clock and more importantly increased your CSS and JavaScript skills significantly.

📚 Materials/References:

CSS Position Tutorial: https://youtu.be/jx5jmI0UlXU
GitHub Code: https://github.com/WebDevSimplified/JavaScript-Clock
Code Pen Code: https://codepen.io/WebDevSimplified/pen/WBbyPW

🧠 Concepts Covered:

– How to use CSS variables in JavaScript
– JavaScript date object
– How to use CSS transform to center elements
– How to use CSS transform to rotate elements on an axis
– Using data attributes as selectors in JavaScript
– Basic CSS pseudo element usage

🌎 Find Me Here:

Twitter: https://twitter.com/DevSimplified
GitHub: https://github.com/WebDevSimplified
CodePen: https://codepen.io/WebDevSimplified

#Clock #JavaScript #CSS

Original source


38 responses to “Build A Clock With JavaScript”

  1. Thanks for this useful tutorial. I am trying to use Emmet in Sublime to do the abbreviation that you used. I have installed Emmet but I cannot seem to activate it. My document is saved as .html but when I type div.number.number$*12{$}*12 nothing happens. Any ideas?

  2. A really nice, enjoyable project. I was expecting it to contain some complex drawing in the JavaScript file. It was very surprising to see that almost all of the work is actually done in the CSS file! Many thanks and really well presented.

  3. Although I do see the solution nice, some things would just fail miserably in older browsers, especially in IE. It should be tested there also, otherwise it's not complete.

  4. It would be nice if the numbers could be positioned at their respective rotational angles while remaining upright. I ended up using an image for the clock face and front bezel, but used the rest of your code as the basis for my clock. Thanks for this!

  5. Great job Web Dev. I really like the pacing of your videos.
    I am having some issues with this one, if anyone can help. I went through the tutorial and typed and double checked with no errors but no hand rotation. I then copied/pasted it from CodePen for the HTML/CSS/Javascript, in case i missed something. My styles and script links are correct ?????? Still no hand movement 🙁

Leave a Reply