File tree Expand file tree Collapse file tree 2 files changed +60
-3
lines changed Expand file tree Collapse file tree 2 files changed +60
-3
lines changed Original file line number Diff line number Diff line change 18
18
19
19
< style >
20
20
html {
21
- background : # 018DED url (http://unsplash.it/1500/1000?image=881&blur=50) ;
21
+ background : # 018DED ;
22
22
background-size : cover;
23
23
font-family : 'helvetica neue' ;
24
24
text-align : center;
55
55
transform : translateY (-3px ); /* account for the height of the clock hands */
56
56
}
57
57
58
+ .clock-face ::after {
59
+ position : absolute;
60
+ content : '' ;
61
+ left : 50% ;
62
+ top : 50% ;
63
+ width : 20px ;
64
+ height : 20px ;
65
+ background : # fff ;
66
+ transform : translate (-50% , -50% );
67
+ border-radius : 50% ;
68
+ }
69
+
58
70
.hand {
59
71
width : 50% ;
60
72
height : 6px ;
61
- background : black;
62
73
position : absolute;
63
74
top : 50% ;
75
+ transform : rotate (90deg );
76
+ transform-origin : right center;
77
+ }
78
+ .hour-hand {
79
+ background : mediumvioletred;
80
+ width : 30% ;
81
+ margin-top : -3px ;
82
+ margin-left : 20% ;
83
+ }
84
+ .min-hand {
85
+ margin-top : -3px ;
86
+ background : mediumspringgreen;
87
+ }
88
+ .second-hand {
89
+ background : greenyellow;
90
+ height : 4px ;
91
+ margin-top : -2px ;
64
92
}
65
93
66
94
</ style >
67
95
68
96
< script >
69
97
98
+ let h , m , s ;
99
+
100
+ // get the current hour min & sec
101
+ function getTime ( ) {
102
+ let current = new Date ( ) ;
103
+ h = current . getHours ( ) ;
104
+ m = current . getMinutes ( ) ;
105
+ s = current . getSeconds ( ) ;
106
+ }
107
+
108
+ // fn to change hour min & sec to angle
109
+ let toAngle = n => ( 90 + n / 60 * 360 ) ;
110
+
111
+ let updateAngle = ( tar , angle ) => {
112
+ tar . style . transform = `rotate(${ angle } deg)` ;
113
+ }
114
+
115
+ let renderClock = ( ) => {
116
+ getTime ( ) ;
117
+ ( ( domObj ) => {
118
+ for ( dom in domObj ) {
119
+ updateAngle ( document . querySelector ( `.${ dom } ` ) , toAngle ( domObj [ dom ] ) )
120
+ }
121
+ } ) ( { 'hour-hand' : h , 'min-hand' : m , 'second-hand' : s } ) ;
122
+ }
123
+
124
+ renderClock ( ) ;
125
+
126
+ setInterval ( renderClock , 1000 ) ;
70
127
71
128
</ script >
72
129
</ body >
Original file line number Diff line number Diff line change 5
5
> Folked repo for practice and fun!
6
6
7
7
1 . [x] ~~ JavaScript Drum Kit~~
8
- 2 . [ ] JS + CSS Clock
8
+ 2 . [x] ~~ JS + CSS Clock ~~
9
9
3 . [ ] CSS Variables
10
10
4 . [ ] Array Cardio, Day 1
11
11
5 . [ ] Flex Panel Gallery
You can’t perform that action at this time.
0 commit comments