File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 66</ head >
77< body >
88
9+ < h1 > JS + CSS CLOCK </ h1 >
910
1011 < div class ="clock ">
1112 < div class ="clock-face ">
6162 background : black;
6263 position : absolute;
6364 top : 50% ;
65+ transform-origin : 100% ;
66+ transform : rotate (90deg );
67+ transition : all 0.05s ;
68+ transition-timing-function : cubic-bezier (0.1 , 2.7 , 0.58 , 1 );
6469 }
6570
6671 </ style >
6772
6873 < script >
6974
75+ const secondHand = document . querySelector ( '.second-hand' ) ;
76+ const minuteHand = document . querySelector ( '.min-hand' ) ;
77+ const hourHand = document . querySelector ( '.hour-hand' ) ;
78+
79+ function setDate ( ) {
80+ // get new date
81+ const now = new Date ( ) ;
82+ // get seconds of current date
83+ const seconds = now . getSeconds ( ) ;
84+ // set seconds to a degree
85+ const secondsDegrees = ( ( seconds / 60 ) * 360 ) + 90 ;
86+ secondHand . style . transform = `rotate(${ secondsDegrees } deg)` ;
87+ // set degree to the transform property
88+
89+ // minute hand
90+ const minutes = now . getMinutes ( ) ;
91+ const minutesDegrees = ( ( minutes / 60 ) * 360 ) + 90 ;
92+ minuteHand . style . transform = `rotate(${ minutesDegrees } deg)` ;
93+
94+ // hour hand
95+
96+ const hours = now . getHours ( ) ;
97+ const hoursDegrees = ( ( hours / 12 ) * 360 ) + 90 ;
98+ hourHand . style . transform = `rotate(${ hoursDegrees } deg)` ;
99+
100+
101+
102+ }
103+
104+ setInterval ( setDate , 1000 )
70105
71106 </ script >
72107</ body >
You can’t perform that action at this time.
0 commit comments