-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTimer.html
116 lines (105 loc) · 3.41 KB
/
Timer.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Countdown Timer</title>
<style>
body {
font-family: 'Roboto', sans-serif;
text-align: center;
margin: 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
min-height: 100vh;
background: linear-gradient(to right, #ffafbd, #ffc3a0); /* Soft pink-orange gradient */
color: #333;
}
h1 {
font-size: 36px;
margin-bottom: 20px;
color: #2c3e50;
text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.1); /* Subtle text shadow */
}
.timer {
font-size: 60px;
color: #34495e; /* Deep blue-gray text color */
margin-bottom: 30px;
padding: 20px;
background-color: rgba(255, 255, 255, 0.2); /* Semi-transparent white background */
border-radius: 15px;
box-shadow: 0 8px 15px rgba(0, 0, 0, 0.2);
transition: transform 0.3s;
}
.timer:hover {
transform: scale(1.05); /* Slight enlargement on hover */
}
button {
padding: 15px 30px;
font-size: 18px;
margin: 10px;
border: none;
border-radius: 25px;
background-color: #ff6b6b; /* Soft coral button color */
color: white;
cursor: pointer;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
transition: background-color 0.3s, transform 0.2s, box-shadow 0.3s;
}
button:hover {
background-color: #e55050; /* Darker coral on hover */
transform: scale(1.1); /* Slightly larger scale on hover */
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
}
button:active {
background-color: #c43d3d; /* Even darker color on click */
transform: scale(1.05);
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}
</style>
</head>
<body>
<h1>Countdown Timer</h1>
<input type="number" id="customTime" placeholder="Enter minutes" min="1" />
<button onclick="setCustomTime()">Set Time</button>
<div class="timer" id="timer">10:00</div>
<button onclick="startTimer()">Start Timer</button>
<button onclick="stopTimer()">Stop Timer</button>
<button onclick="resetTimer()">Reset Timer</button>
<script>
let time = 600; // 10 minutes in seconds
let timer;
function startTimer() {
if (timer) return; // prevent multiple timers
timer = setInterval(function() {
let minutes = Math.floor(time / 60);
let seconds = time % 60;
document.getElementById('timer').textContent = `${minutes}:${seconds < 10 ? '0' : ''}${seconds}`;
time--;
if (time < 0) {
clearInterval(timer);
timer = null;
alert('Time is up!');
}
}, 1000);
}
function stopTimer() {
clearInterval(timer);
timer = null; // reset timer to allow restarting
}
function resetTimer() {
clearInterval(timer);
timer = null;
time = 600;
document.getElementById('timer').textContent = '10:00';
}
function setCustomTime() {
const input = document.getElementById('customTime').value;
time = input * 60; // Convert minutes to seconds
document.getElementById('timer').textContent = `${Math.floor(time / 60)}:00`; // Update timer display
}
</script>
</body>
</html>