- [Instructor] In the exercise files for this movie, 06_02, you'll find the starting point for our analog clock. If you look at the markup you'll see in index dot HTML we have just a container called clock box and inside sits an inline svg. I've marked up this svg so it's easy to understand what each of the pieces are. Here we have three graphs. So this is the face, that is the circle around the clock and the hour marks. Then we have the hour hand, the minute hand and the second hand.
And we're going to target these using the id's later. Inside each of these graphic components we have svg markup for different things. So here I can see inside the face we have the circle, we have the hour marks and then we have the mid circle that is in the center. For the hour we have the hour arm and a sizing box. For the minute we have the minute arm and a sizing box. And for the seconds we have a second arm and a sizing box. Looking at the CSS it is about as sparse as can be. We center the content using flex and the main element and the clock box container.
Then I have specific styling for each of the elements within the svg. So here we have the circle. You can see the stroke is set to black, the stroke width is nine and the stroke miter limit is 10. You can mess around with these values and see how it changes the graphic later. The mid circle is a little dot in the center of the clock. It is just black. Then we have the hour marks which are the ticks around the clock face. Again, they're black and we have a width. Then we have the hour arm, the minute arm and the second arm. And here you see the hour arm is the thickest.
Then the minute arm is not as thick and then the second arm is very thin. Finally, there's this element, the sizing box. The sizing box is just used to center the arms so they rotate correctly around the same axis. So you shouldn't do anything to that. If you try to put a fill color on it you'll see the entire clock face will change color. So just ignore that part. And at the very bottom we have a grouped styling that applies to all three of the arms. Here we have transform origin 300 by 300. This just centers the transforms around the center of the graphic.
And then we have transition that transitions how the arms move. This is what your clock face currently looks like. This is a layered svg and you can scale it to any size in the browser. We can also manipulate all the different elements here using CSS. So, if I inspect any element within here. You see here we have the svg. Then we can burrow down into, say, the clock face. Here we have the circle element. If we change the color here to red we see the circle turns red.
If you change the stroke width we can make it thicker or thinner. And basically we can just mess around with this to make it look pretty much like anything we want. Our main task in this example project is to get the hour, minute and second arms to move around the circle to actually show the current time. And we're going to do that using the transform property in CSS. So if we look in here you see we have hour, minute and second as id's.
And I can create rules for each of these. So let's say I want to move just the minute arm. I can say minute. Then put in transform rotate and then parenthesis. Then the number of degrees, so maybe 15 degrees. And here you see the arm moves. Now you can go in and change the value and you see the clock arm rotates for me. And this is what we're going to do using JavaScript.
Apply the transform property as an inline CSS style.
Author
Updated
4/1/2019Released
5/17/2017Through practical examples and mini-projects, this course helps you build your understanding of JavaScript piece by piece, from core principles like variables, data types, conditionals, and functions through advanced topics including loops, closures, and DOM scripting. Along the way, you will also be introduced to some ES6 and the basics of JavaScript libraries.
- What is JavaScript?
- Working with data
- Using functions and objects
- Working with JavaScript and the DOM
- Changing DOM elements
- Handling events
- Working with loops
- Making images responsive using markup
- Troubleshooting code
- Validating functionality
- Minifying JavaScript
Skill Level Beginner
Duration
Views
Related Courses
-
Introduction
-
Welcome1m 7s
-
-
1. JavaScript: An Introduction
-
What is JavaScript?2m 38s
-
-
2. The Basics
-
Introducing the browser console10m 31s
-
3. Working with data
-
Data types in JavaScript4m 2s
-
Arrays2m 20s
-
4. Functions and Objects
-
Functions in JavaScript3m 28s
-
Build a basic function3m 29s
-
Anonymous functions5m 11s
-
Variable scope3m 17s
-
ES2015: let and const6m 12s
-
Make sense of objects3m 19s
-
Object constructors6m 16s
-
Closures8m 11s
-
-
5. JavaScript and the DOM, Part 1: Changing DOM Elements
-
Access and change elements4m 33s
-
Access and change classes3m 45s
-
Access and change attributes4m 53s
-
Add DOM elements6m 56s
-
6. Project: Create an Analog Clock
-
Use CSS to move clock hands3m 49s
-
7. JavaScript and the DOM, Part 2: Events
-
What are DOM events?1m 31s
-
Some typical DOM events1m 59s
-
Add and use event listeners6m 51s
-
-
8. Project: Typing Speed Tester
-
Rundown of HTML markup2m 58s
-
Build a count-up timer5m 56s
-
Add a reset button5m 3s
-
-
9. Loops
-
Loops3m 37s
-
Looping through arrays4m 7s
-
Break and continue loops7m 9s
-
-
10. Project: Automated Responsive Images Markup
-
Project breakdown1m 55s
-
Rundown of project setup3m 26s
-
-
11. Troubleshooting, Validating, and Minifying JavaScript
-
Troubleshooting JavaScript7m 20s
-
Online script linting5m 57s
-
Automate script linting8m 24s
-
Online script minification2m 50s
-
Automate script minification2m 24s
-
12. Bonus Chapter: Ask the Instructor
-
What are arrow functions?3m 11s
-
What does the % symbol do?3m 47s
-
-
Conclusion
-
Next Steps1m 55s
-
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.
CancelTake notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.
Share this video
Embed this video
Video: Use CSS to move clock hands