File tree 1 file changed +37
-2
lines changed
1 file changed +37
-2
lines changed Original file line number Diff line number Diff line change 58
58
59
59
.hand {
60
60
width : 50% ;
61
- height : 6 px ;
61
+ height : 2 px ;
62
62
background : black;
63
63
position : absolute;
64
- top : 50% ;
64
+ top : calc (50% - 1px );
65
+ transform-origin : 100% ;
66
+ transform : rotate (90deg );
67
+ transition-timing-function : cubic-bezier (0 , 1.21 , 0.51 , 1.03 );
68
+ }
69
+
70
+ .hour-hand {
71
+ width : 35% ;
72
+ height : 6px ;
73
+ left : 15% ;
74
+ top : calc (50% - 3px );
75
+ }
76
+
77
+ .min-hand {
78
+ width : 45% ;
79
+ height : 4px ;
80
+ left : 5% ;
81
+ top : calc (50% - 2px );
65
82
}
66
83
67
84
</ style >
68
85
69
86
< script >
87
+ const hoursHand = document . querySelector ( `.hour-hand` ) ;
88
+ const minsHand = document . querySelector ( `.min-hand` ) ;
89
+ const secondsHand = document . querySelector ( `.second-hand` ) ;
90
+
91
+ function setDate ( ) {
92
+ const now = new Date ( ) ;
93
+ const hours = now . getHours ( ) ;
94
+ const mins = now . getMinutes ( ) ;
95
+ const seconds = now . getSeconds ( ) ;
96
+ const hoursDegrees = ( hours / 12 ) * 360 + ( mins / 60 ) * 360 / 12 + 90 ; //adding mins angles as well.. to avoid the hour hand jumping each hour
97
+ const minsDegrees = ( mins / 60 ) * 360 + ( seconds / 60 ) * 360 / 60 + 90 ; //adding seconds angles as well.. to avoid the hour hand jumping each minute
98
+ const secondsDegrees = ( seconds / 60 ) * 360 + 90 ;
99
+
100
+ hoursHand . style . transform = `rotate(${ hoursDegrees } deg)` ;
101
+ minsHand . style . transform = `rotate(${ minsDegrees } deg)` ;
102
+ secondsHand . style . transform = `rotate(${ secondsDegrees } deg)` ;
103
+ }
70
104
105
+ setInterval ( setDate , 1000 ) ;
71
106
72
107
</ script >
73
108
</ body >
You can’t perform that action at this time.
0 commit comments