File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 6161 background : black;
6262 position : absolute;
6363 top : 50% ;
64+ transform-origin : 100% ; /* move rotation point from middle of the segment to right margin */
65+ transform : rotate (90deg ); /*start all from 12:00*/
66+ transition : all 0.05s ;
67+ transition-timing-function : cubic-bezier (0.1 , 2.7 , 0.58 , 1 );
6468 }
6569
6670 </ style >
6771
6872 < script >
6973
74+ const secondHand = document . querySelector ( '.second-hand' ) ;
75+ const minuteHand = document . querySelector ( '.min-hand' ) ;
76+ const hourHand = document . querySelector ( '.hour-hand' ) ;
77+
78+ function setDate ( ) {
79+ const now = new Date ( ) ;
80+ const seconds = now . getSeconds ( ) ;
81+ const secondsDegree = ( ( seconds / 60 ) * 360 ) + 90 ;
82+
83+ const minutes = now . getMinutes ( ) ;
84+ const minutesDegree = ( ( minutes / 60 ) * 360 ) + 90 ;
85+
86+ const hours = now . getHours ( ) ;
87+ const hoursDegree = ( ( hours / 12 ) * 360 ) + 90 ;
88+
89+ secondHand . style . transform = `rotate(${ secondsDegree } deg)` ;
90+ minuteHand . style . transform = `rotate(${ minutesDegree } deg)` ;
91+ hourHand . style . transform = `rotate(${ hoursDegree } deg)` ;
92+ }
93+
94+ setInterval ( setDate , 1000 ) ;
7095
7196 </ script >
7297</ body >
You can’t perform that action at this time.
0 commit comments