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 1818
1919 < style >
2020 html {
21- background : # 018DED url (http://unsplash.it/1500/1000?image=881&blur=50) ;
21+ background : # 018DED ;
2222 background-size : cover;
2323 font-family : 'helvetica neue' ;
2424 text-align : center;
5555 transform : translateY (-3px ); /* account for the height of the clock hands */
5656 }
5757
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+
5870 .hand {
5971 width : 50% ;
6072 height : 6px ;
61- background : black;
6273 position : absolute;
6374 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 ;
6492 }
6593
6694 </ style >
6795
6896 < script >
6997
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 ) ;
70127
71128 </ script >
72129</ body >
Original file line number Diff line number Diff line change 55> Folked repo for practice and fun!
66
771 . [x] ~~ JavaScript Drum Kit~~
8- 2 . [ ] JS + CSS Clock
8+ 2 . [x] ~~ JS + CSS Clock ~~
993 . [ ] CSS Variables
10104 . [ ] Array Cardio, Day 1
11115 . [ ] Flex Panel Gallery
You can’t perform that action at this time.
0 commit comments