-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.html
37 lines (34 loc) · 1.27 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
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="styles.css" />
<script>
function startTimer() {
const endTime = Date.now() + 5 * 60 * 1000; // 5 minutes from now
const timer = setInterval(() => {
const remainingTime = endTime - Date.now();
if (remainingTime <= 0) {
clearInterval(timer);
document.getElementById("timer").innerHTML = 'Offer expired!';
document.getElementById("message").remove();
} else {
const minutes = Math.floor(remainingTime / 1000 / 60);
const seconds = Math.floor((remainingTime / 1000) % 60).toString().padStart(2, '0');
document.getElementById("timer").innerHTML = minutes + ":" + seconds;
}
}, 1000);
}
window.addEventListener("load", startTimer);
</script>
<title>Online - Clock</title>
</head>
<body>
<div class="wrapper">
<div class="clock" id="timer">05:00</div>
<p class="text" id="message">Flash offer </p>
<p class="text">Timer using Date.now() and setInterval</p>
</div>
</body>
</html>