File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 62
62
background : black;
63
63
position : absolute;
64
64
top : 50% ;
65
+ transform-origin : 100% ;
66
+ transform : rotate (90deg );
65
67
}
66
68
67
69
</ style >
68
70
69
71
< script >
72
+ const secondHand = document . querySelector ( '.second-hand' ) ;
73
+ const minHand = document . querySelector ( '.min-hand' ) ;
74
+ const hourHand = document . querySelector ( '.hour-hand' ) ;
75
+ const hands = document . querySelectorAll ( '.hand' ) ;
70
76
77
+ function setDate ( ) {
78
+ const now = new Date ( ) ;
79
+ const seconds = now . getSeconds ( ) ;
80
+ const secondsDegrees = ( ( seconds / 60 ) * 360 ) + 90 ;
81
+ secondHand . style . transform = `rotate(${ secondsDegrees } deg)`
71
82
83
+ const mins = now . getMinutes ( ) ;
84
+ const minsDegrees = ( ( mins / 60 ) * 360 ) + 90 ;
85
+ minHand . style . transform = `rotate(${ minsDegrees } deg)` ;
86
+
87
+ const hours = now . getHours ( ) ;
88
+ const hoursDegrees = ( ( hours / 12 ) * 360 ) + 90 ;
89
+ hourHand . style . transform = `rotate(${ hoursDegrees } deg)` ;
90
+
91
+ if ( seconds === 0 ) {
92
+ [ ...hands ] . forEach ( function ( hand ) {
93
+ hand . style . transition = 'none' ;
94
+ } )
95
+ } else {
96
+ [ ...hands ] . forEach ( function ( hand ) {
97
+ hand . style . transition = 'all .25s' ;
98
+ } )
99
+ }
100
+ }
101
+
102
+ setInterval ( setDate , 1000 )
72
103
</ script >
73
104
</ body >
74
105
</ html >
You can’t perform that action at this time.
0 commit comments