File tree Expand file tree Collapse file tree 5 files changed +65
-0
lines changed
Expand file tree Collapse file tree 5 files changed +65
-0
lines changed Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < title > Clock demo</ title >
6+
7+ < style >
8+ body {
9+ display : flex;
10+ justify-content : center;
11+ align-items : center;
12+ height : 100vh ;
13+ background : white;
14+ }
15+
16+ .clock {
17+ position : relative;
18+ width : 300px ;
19+ height : 300px ;
20+ }
21+
22+ .hand {
23+ position : absolute;
24+ top : 50% ;
25+ left : 50% ;
26+ transform-origin : 50% 50% ; /* center */
27+ transform : translate (-50% , -50% ) rotate (0deg );
28+ }
29+
30+ /* Optional sizing */
31+ # hours { height : 600px ; }
32+ # minutes { height : 600px ; }
33+ # seconds { height : 600px ; }
34+ </ style >
35+ </ head >
36+
37+ < body >
38+ < div class ="clock ">
39+ < img src ="hours.png " id ="hours " class ="hand ">
40+ < img src ="minutes.png " id ="minutes " class ="hand ">
41+ < img src ="seconds.png " id ="seconds " class ="hand ">
42+ </ div >
43+
44+ < script >
45+ const h = document . getElementById ( "hours" ) ;
46+ const m = document . getElementById ( "minutes" ) ;
47+ const s = document . getElementById ( "seconds" ) ;
48+
49+ function updateClock ( ) {
50+ const now = new Date ( ) ;
51+
52+ const seconds = now . getSeconds ( ) ;
53+ const minutes = now . getMinutes ( ) + seconds / 60 ;
54+ const hours = ( now . getHours ( ) % 12 ) + minutes / 60 ;
55+
56+ h . style . transform = `translate(-50%, -50%) rotate(${ hours * 30 } deg)` ;
57+ m . style . transform = `translate(-50%, -50%) rotate(${ minutes * 6 } deg)` ;
58+ s . style . transform = `translate(-50%, -50%) rotate(${ seconds * 6 } deg)` ;
59+ }
60+
61+ updateClock ( ) ;
62+ setInterval ( updateClock , 10 ) ;
63+ </ script >
64+ </ body >
65+ </ html >
You can’t perform that action at this time.
0 commit comments