-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patht2.html
More file actions
178 lines (157 loc) · 5.1 KB
/
t2.html
File metadata and controls
178 lines (157 loc) · 5.1 KB
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
background-color: #f2f2f2;
animation: colorChange 10s linear infinite alternate;
}
@keyframes colorChange {
0% {
background-color: #3498db;
}
25% {
background-color: #e74c3c;
}
50% {
background-color: #f1c40f;
}
75% {
background-color: #27ae60;
}
100% {
background-color: #9b59b6;
}
}
.stopwatch {
margin: 100px auto;
width: 300px;
background-color: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
animation: moveIn 1s ease;
}
@keyframes moveIn {
0% {
transform: translateY(-200px);
opacity: 0;
}
100% {
transform: translateY(0);
opacity: 1;
}
}
h1 {
font-size: 28px;
color: #333;
margin-bottom: 20px;
}
p {
font-size: 24px;
margin: 10px 0;
color: #333;
}
.controls button {
margin: 5px;
padding: 8px 15px;
font-size: 18px;
border: none;
background-color: #3498db;
color: #fff;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}
.controls button:hover {
background-color: #2980b9;
}
.controls button:active {
background-color: #1f6690;
}
.lap-button {
background-color: #27ae60;
}
.lap-button:hover {
background-color: #1e9843;
}
.lap-button:active {
background-color: #167e39;
}
</style>
</head>
<body>
<div class="stopwatch">
<h1>Stopwatch</h1>
<p id="display">00:00:00</p>
<div class="controls">
<button id="startStop" onclick="startStop()">Start</button>
<button onclick="pause()">Pause</button>
<button onclick="reset()">Reset</button>
<button class="lap-button" onclick="lap()">Lap</button>
</div>
<ul id="laps"></ul>
</div>
<script>
let colorIndex = 0;
const colors = ['#3498db', '#e74c3c', '#f1c40f', '#27ae60', '#9b59b6'];
function changeBackgroundColor() {
document.body.style.backgroundColor = colors[colorIndex];
colorIndex = (colorIndex + 1) % colors.length;
}
setInterval(changeBackgroundColor, 10000);
let timer;
let isRunning = false;
let startTime;
let currentTime;
function startStop() {
const startStopButton = document.getElementById('startStop');
if (isRunning) {
clearInterval(timer);
isRunning = false;
startStopButton.textContent = 'Start';
} else {
isRunning = true;
startTime = Date.now() - (currentTime || 0);
timer = setInterval(updateDisplay, 10);
startStopButton.textContent = 'Stop';
}
}
function updateDisplay() {
currentTime = Date.now() - startTime;
const formattedTime = formatTime(currentTime);
document.getElementById('display').textContent = formattedTime;
}
function pause() {
clearInterval(timer);
isRunning = false;
document.getElementById('startStop').textContent = 'Start';
}
function reset() {
clearInterval(timer);
isRunning = false;
currentTime = 0;
document.getElementById('display').textContent = '00:00:00';
document.getElementById('laps').innerHTML = '';
document.getElementById('startStop').textContent = 'Start';
}
function lap() {
if (isRunning) {
const formattedTime = formatTime(currentTime);
const lapItem = document.createElement('li');
lapItem.textContent = formattedTime;
document.getElementById('laps').appendChild(lapItem);
}
}
function formatTime(time) {
const date = new Date(time);
const minutes = date.getMinutes().toString().padStart(2, '0');
const seconds = date.getSeconds().toString().padStart(2, '0');
const milliseconds = date.getMilliseconds().toString().padStart(3, '0');
return `${minutes}:${seconds}:${milliseconds}`;
}
</script>
</body>
</html>