forked from wesbos/JavaScript30
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyScript.js
More file actions
27 lines (22 loc) · 1.13 KB
/
myScript.js
File metadata and controls
27 lines (22 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// The querySelector() method returns the first element that matches a specified CSS selector(s) in the document.
const secondHand = document.querySelector('.second-hand');
const minsHand = document.querySelector('.min-hand');
const hourHand = document.querySelector('.hour-hand');
function setDate() {
var date = new Date();
var hours = date.getHours();
var minutes = date.getMinutes();
var seconds = date.getSeconds();
const secDegrees = ((seconds / 60) * 360) + 90;
const minDegrees = ((minutes / 60) * 360) + 90;
const hourDegrees = ((hours / 12) * 360) + 90;
secondHand.style.transform = `rotate(${secDegrees}deg)`;
minsHand.style.transform = `rotate(${minDegrees}deg)`;
hourHand.style.transform = `rotate(${hourDegrees}deg)`;
}
//The setInterval() method calls a function or evaluates an expression at specified intervals (in milliseconds).
//The setInterval() method will continue calling the function until clearInterval() is called, or the window is closed.
//The ID value returned by setInterval() is used as the parameter for the clearInterval() method.
//Tip: 1000 ms = 1 second.
setInterval(setDate, 1000);
setDate();