-
Notifications
You must be signed in to change notification settings - Fork 0
/
compteur.html
98 lines (83 loc) · 2.64 KB
/
compteur.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
<!DOCTYPE html>
<html>
<head>
<title>Compte à rebours</title>
<style>
::before, ::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: Arial, Helvetica, sans-serif;
background: #222;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
background-image: url(./moi.png);
background-size: cover;
background-repeat: no-repeat;
position: relative;
}
body::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.1);
}
#countdown {
font-size: 800%;
text-align: center;
color: #ffffff;
}
.bold {
font-weight: bold;
}
</style>
</head>
<body>
<div id="countdown"></div>
<script>
function countdown(endDate) {
const countdownElement = document.getElementById('countdown');
const startDate = new Date();
const startTime = startDate.getTime();
const endTime = endDate.getTime();
let timeDiff = endTime - startTime;
if (timeDiff <= 0) {
countdownElement.innerHTML = "La date de fin doit être supérieure à la date de départ.";
return;
}
const countdownInterval = setInterval(() => {
timeDiff -= 1000;
let days = Math.floor(timeDiff / (1000 * 60 * 60 * 24));
let hours = Math.floor((timeDiff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
let minutes = Math.floor((timeDiff % (1000 * 60 * 60)) / (1000 * 60));
let seconds = Math.floor((timeDiff % (1000 * 60)) / 1000);
countdownElement.innerHTML = "Temps restant<br><br>";
countdownElement.innerHTML += "<b>" + days + "</b>j, "
countdownElement.innerHTML += "<b>" + hours + "</b>h, ";
countdownElement.innerHTML += "<b>" + minutes + "</b>m, ";
countdownElement.innerHTML += "<b>" + seconds + "</b>s";
const hoursOnly = Math.floor(timeDiff / (1000 * 60 * 60));
countdownElement.innerHTML += "<br><br><b>" + hoursOnly + "</b> heures";
const minutesOnly = Math.floor(timeDiff / (1000 * 60));
countdownElement.innerHTML += "<br><br><b>" + minutesOnly + "</b> minutes";
const secondsOnly = Math.floor(timeDiff / 1000);
countdownElement.innerHTML += "<br><br><b>" + secondsOnly + "</b> secondes";
if (timeDiff <= 0) {
clearInterval(countdownInterval);
countdownElement.innerHTML = "Le compte à rebours est terminé !";
}
}, 1000);
}
const endDate = new Date("2023-07-24T20:22:00");
countdown(endDate);
</script>
</body>
</html>