-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
166 lines (142 loc) · 4.45 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Beautiful Clock</title>
<style>
body {
background-color: #2c3e50;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
font-family: 'Arial', sans-serif;
}
#clock-container {
height: 300px;
width: 300px;
border-radius: 50%;
position: relative;
background: radial-gradient(circle, #3498db, #2980b9);
box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
overflow: hidden;
transition: transform 0.2s, box-shadow 0.2s;
}
#second-hand, #minute-hand, #hour-hand {
position: absolute;
transform-origin: left;
top: 50%;
left: 50%;
}
#second-hand {
height: 2px;
width: 125px;
border-style: solid;
border-color: #ecf0f1;
border-width: 2px;
transform: rotate(-90deg);
z-index: 3;
}
#minute-hand {
height: 4px;
width: 120px;
border-style: solid;
border-color: #ecf0f1;
border-width: 3px;
transform: rotate(-90deg);
z-index: 2;
}
#hour-hand {
height: 6px;
width: 100px;
border-style: solid;
border-color: #ecf0f1;
border-width: 4px;
transform: rotate(-90deg);
z-index: 1;
}
/* Add a decorative pattern to the clock */
#clock-container::before {
content: '';
position: absolute;
width: 100%;
height: 100%;
background: url('https://source.unsplash.com/300x300/?pattern') repeat;
opacity: 0.3;
border-radius: 50%;
}
#clock-container.clicked {
transform: scale(1.2);
box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
}
</style>
</head>
<body>
<div id="clock-container" onclick="toggleClock()">
<div id="second-hand"></div>
<div id="minute-hand"></div>
<div id="hour-hand"></div>
</div>
<script>
var intervalId;
var seconds = 0;
var minutes = 0;
var hours = 0;
var isClockRunning = false;
// Function to initialize the clock with the current time
var initializeClock = function() {
var currentTime = new Date();
seconds = currentTime.getSeconds();
minutes = currentTime.getMinutes();
hours = currentTime.getHours() % 12;
updateClockHands();
// Uncomment the line below if you want the clock to start automatically
// startClock();
};
var startClock = function() {
if (!isClockRunning) {
intervalId = setInterval(tickSecond, 1000);
isClockRunning = true;
}
}
var stopClock = function() {
clearInterval(intervalId);
isClockRunning = false;
}
var toggleClock = function() {
var clockContainer = document.getElementById("clock-container");
if (isClockRunning) {
stopClock();
} else {
startClock();
}
// Add or remove 'clicked' class to apply styling changes
clockContainer.classList.toggle("clicked", isClockRunning);
}
var tickSecond = function() {
seconds = (seconds + 1) % 60;
updateClockHands();
if (seconds % 60 === 0) {
minutes = (minutes + 1) % 60;
updateClockHands();
if (minutes % 60 === 0) {
hours = (hours + 1) % 12;
updateClockHands();
}
}
};
var updateClockHands = function() {
var secondHand = document.getElementById("second-hand");
var minuteHand = document.getElementById("minute-hand");
var hourHand = document.getElementById("hour-hand");
secondHand.style.transform = "rotate(" + (seconds * 6 - 90) + "deg)";
minuteHand.style.transform = "rotate(" + (minutes * 6 - 90) + "deg)";
hourHand.style.transform = "rotate(" + (hours * 30 - 90) + "deg)";
}
// Call the initializeClock function when the page loads
initializeClock();
</script>
</body>
</html>