-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathscript.js
More file actions
39 lines (31 loc) · 1.72 KB
/
script.js
File metadata and controls
39 lines (31 loc) · 1.72 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
( function( $ ) {
// Set the date we're counting down to
var countDownDate = new Date("Jan 01, 2018 08:00:00").getTime();
// Update the count down every 1 second
var x = setInterval(function() {
// Get todays date and time
var now = new Date().getTime();
// Find the distance between now an the count down date
var distance = countDownDate - now;
// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
// Display the result in the element with id=""
//
// Option 1 - All in one line
// document.getElementById("countdown").innerHTML = days + "days " + hours + "h " + minutes + "m " + seconds + "s ";
//
// Option 2 - Breakout into seperate divs and display individual values
document.getElementById("countdowndays").innerHTML = '<div class="cd-num">' + days + '</div> DAYS';
document.getElementById("countdownhours").innerHTML = '<div class="cd-num">' + hours + '</div> HRS';
document.getElementById("countdownmins").innerHTML = '<div class="cd-num">' + minutes + '</div> MINS';
document.getElementById("countdownsecs").innerHTML = '<div class="cd-num">' + seconds + '</div> SECS';
// If the count down is finished, hide the containing div
if (distance < 0) {
clearInterval(x);
document.getElementById("countdown").style.display = "none";
}
}, 1000);
} )( jQuery );