forked from naveen3011/WebD_project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCountdownTIMER-1-main.html
128 lines (98 loc) · 2.88 KB
/
CountdownTIMER-1-main.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!-- <link rel="stylesheet" href="style.css"> -->
</head>
<body>
<h1>New Years Eve</h1>
<div class="con">
<!-- inside it we have days , hours , min and Sec Container -->
<div class="whole-elem days-con">
<p class="big-text" id="days">0</p>
<span>Days</span>
</div>
<div class="whole-elem hours-con">
<p class="big-text" id="hours">0</p>
<span>Hours</span>
</div>
<div class="whole-elem mins-con">
<p class="big-text" id="mins">0</p>
<span>Minutes</span>
</div>
<div class="whole-elem seconds-con">
<p class="big-text" id="sec">0</p>
<span>Seconds</span>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
###--------js-------#
let daysEl = document.getElementById('days');
let hourEl = document.getElementById('hours');
let minEl = document.getElementById('mins');
let secEl = document.getElementById('sec');
function countdown(){
var currentTime= new Date().getTime(); // Curent Time
const newYear = new Date("dec 31, 2021 23:59:59").getTime(); // destination time
var difference = newYear - currentTime;
// you have got the answere but in milliseconds
var seconds,hours,days,minutes;
seconds = Math.floor((difference%(1000*60)/1000));
minutes = Math.floor(difference%(1000*60*60)/(1000*60));
hours = Math.floor((difference%(1000*60*60*24))/(1000*60*60));
days = Math.floor(difference/(1000*60*60*24));
daysEl.innerHTML = days;
hourEl.innerHTML =Timeformat(hours);
minEl.innerHTML = Timeformat(minutes);
secEl.innerHTML = Timeformat(seconds);
};
function Timeformat (time) {
if(time < 10)
return (`0${time}`);
else
return time;
}
setInterval(countdown,1000) //Updtaes the function every 1 sec
// 1000ms = 1 sec
##########--------CSS--------############
@import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,400;1,200&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Ubuntu:ital,wght@1,500&display=swap');
*{
box-sizing: border-box;
}
body{
margin: 0px;
background: url('Images/bg1.jpg') no-repeat;
background-size: cover;
/* background-position: center center; */
min-height: 100vh;
font-family: 'Poppins', sans-serif;
display: flex;
flex-direction: column;
align-items: center;
}
h1{
font-size: 4.2rem;
font-weight: 400;
margin-top: 5rem;
}
.whole-elem{
text-align: center;
}
.con{
display: flex;
/* border: 5px solid #ffffff9c;
padding: 15px 70px ; */
}
.big-text{
text-align: center;
font-size: 6rem;
margin: 0px 60px;
}
.whole-elem span{
font-size: 1.7rem;
}