File tree Expand file tree Collapse file tree 2 files changed +19
-101
lines changed
Expand file tree Collapse file tree 2 files changed +19
-101
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 6868
6969 < script >
7070 const hourHand = document . querySelector ( ".hour-hand" ) ;
71- const minHand = document . querySelector ( ".minsr -hand" ) ;
71+ const minHand = document . querySelector ( ".min -hand" ) ;
7272 const secondHand = document . querySelector ( ".second-hand" ) ;
73+
74+ const handDegreeChange = ( time , max ) => ( time / max ) * 360 ;
75+
76+ // Call function once every second
77+ setInterval ( ( ) => {
78+ const currentTime = new Date ( ) ;
79+ // Get current seconds, minutes, & hours and calculate the degree shift
80+ const hourHandDegrees = handDegreeChange ( currentTime . getHours ( ) , 12 ) ;
81+ const minHandDegrees = handDegreeChange ( currentTime . getMinutes ( ) , 60 ) ;
82+ const secondHandDegrees = handDegreeChange (
83+ currentTime . getSeconds ( ) ,
84+ 60
85+ ) ;
86+ //Apply rotation to clock hands with current time
87+ hourHand . style . transform = `rotate(${ hourHandDegrees } deg)` ;
88+ minHand . style . transform = `rotate(${ minHandDegrees } deg)` ;
89+ secondHand . style . transform = `rotate(${ secondHandDegrees } deg)` ;
90+ } , 1000 ) ;
7391 </ script >
7492 </ body >
7593</ html >
You can’t perform that action at this time.
0 commit comments