1
1
<!DOCTYPE html>
2
2
< html lang ="en ">
3
3
< head >
4
- < meta charset ="UTF -8 ">
5
- < title > JS + CSS Clock</ title >
4
+ < meta charset ="utf -8 ">
5
+ < title > JS + CSS Clock</ title >
6
6
</ head >
7
7
< body >
8
8
9
-
10
- < div class ="clock ">
11
- < div class ="clock-face ">
12
- < div class ="hand hour-hand "> </ div >
13
- < div class ="hand min-hand "> </ div >
14
- < div class ="hand second-hand "> </ div >
15
- </ div >
9
+ < div class ="clock ">
10
+ < div class ="clock-face ">
11
+ < div class ="hand hour-hand "> </ div >
12
+ < div class ="hand min-hand "> </ div >
13
+ < div class ="hand second-hand "> </ div >
16
14
</ div >
17
-
15
+ </ div >
18
16
19
17
< style >
20
18
html {
21
- background : # 018DED url (http://unsplash.it/1500/1000?image=881&blur=50);
22
- background-size : cover;
23
- font-family : 'helvetica neue' ;
24
- text-align : center;
25
- font-size : 10px ;
19
+ background : # 018DED url (http://unsplash.it/1500/1000?image=881&blur=50);
26
20
}
27
21
28
22
body {
36
30
.clock {
37
31
width : 30rem ;
38
32
height : 30rem ;
39
- border : 20px solid white ;
33
+ border : 20px solid hotpink ;
40
34
border-radius : 50% ;
41
35
margin : 50px auto;
42
36
position : relative;
52
46
position : relative;
53
47
width : 100% ;
54
48
height : 100% ;
55
- transform : translateY (-3px ); /* account for the height of the clock hands */
49
+ transform : translateY (-3px );
56
50
}
57
51
58
52
.hand {
59
- width : 50% ;
60
- height : 6px ;
61
- background : black;
53
+ width : 50% ;
54
+ height : 6px ;
55
+ background : black;
62
56
position : absolute;
63
- top : 50% ;
57
+ top : 50% ;
64
58
transform-origin : 100% ;
65
59
transform : rotate (90deg );
66
60
transition : all 0.05s ;
61
+ /*add 'if' stateement to above transition to remove glitch when clock hits 60*/
67
62
transition-timing-function : cubic-bezier (0.1 , 2.7 , 0.58 , 1 );
68
63
}
69
- </ style >
70
64
71
- < script >
72
- const secondHand = document . querySelector ( '.second-hand' ) ;
73
- const minsHand = document . querySelector ( '.min-hand' ) ;
74
- const hourHand = document . querySelector ( '.hour-hand' ) ;
65
+ </ style >
66
+ < script >
67
+ const secondHand = document . querySelector ( '.second-hand' ) ;
68
+ const minuteHand = document . querySelector ( '.min-hand' ) ;
69
+ const hourHand = document . querySelector ( '.hour-hand' ) ;
75
70
76
- function setDate ( ) {
77
- const now = new Date ( ) ;
71
+ function setDate ( ) {
72
+ const now = new Date ( ) ;
78
73
79
- const seconds = now . getSeconds ( ) ;
80
- const secondsDegrees = ( ( seconds / 60 ) * 360 ) + 90 ;
81
- secondHand . style . transform = `rotate(${ secondsDegrees } deg)` ;
74
+ const seconds = now . getSeconds ( ) ;
75
+ const secondsDegrees = ( ( seconds / 60 ) * 360 + 90 ) ;
76
+ secondHand . style . transform = `rotate(${ secondsDegrees } deg)` ;
77
+ console . log ( "seconds" , seconds ) ;
82
78
83
- const mins = now . getMinutes ( ) ;
84
- const minsDegrees = ( ( mins / 60 ) * 360 ) + 90 ;
85
- minsHand . style . transform = `rotate(${ minsDegrees } deg)` ;
79
+ const minutes = now . getMinutes ( ) ;
80
+ const minuteDegrees = ( ( minutes / 60 ) * 360 + 90 ) ;
81
+ minuteHand . style . transform = `rotate(${ minuteDegrees } deg)` ;
82
+ console . log ( "mins" , minutes ) ;
86
83
87
- const hour = now . getMinutes ( ) ;
88
- const hourDegrees = ( ( mins / 12 ) * 360 ) + 90 ;
89
- hourHand . style . transform = `rotate(${ hourDegrees } deg)` ;
90
- }
91
-
92
- setInterval ( setDate , 1000 ) ;
84
+ const hours = now . getHours ( ) ;
85
+ const hourDegrees = ( ( hours / 60 ) * 360 + 90 ) ;
86
+ hourHand . style . transform = `rotate(${ hourDegrees } deg)` ;
87
+ console . log ( "hours" , hours ) ;
88
+ }
93
89
94
- </ script >
90
+ setInterval ( setDate , 1000 ) ;
91
+ </ script >
95
92
</ body >
96
- </ html >
93
+ </ html >
0 commit comments