-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
89 lines (85 loc) · 2.9 KB
/
index.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
<html>
<head>
<title>How long until 31c3?</title>
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:200,400,200italic' rel='stylesheet' type='text/css'>
<style>
body {
font-family: 'Source Sans Pro', sans-serif;
background-color: white;
background-image: url(30c3.jpg);
background-size:100%;
background-repeat:no-repeat;
color: white;
font-size: 100px;
font-weight: 100;
}
.countdown {
max-width:800px;
margin:auto;
text-align: center;
}
.countdownElement {
display: inline-block;
}
.foo {
/*display:block;*/
font-size:20px;
}
</style>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<div class="countdown" style="padding-top:100px;" data-targetdate="2014-12-27T10:00+01:00">
<div class="countdownElement"><span class="days">0</span><span class="foo">d </span></div>
<div class="countdownElement"><span class="hours">0</span><span class="foo">h </span></div>
<div class="countdownElement"><span class="minutes">0</span><span class="foo">m </span></div>
<div class="countdownElement"><span class="seconds">0</span><span class="foo">s</span></div>
</div>
</body>
<script>
var countDown = $('.countdown');
console.log($('.countdown').data("targetdate"));
var days = $('.days'),
hours = $('.hours'),
minutes = $('.minutes'),
seconds = $('.seconds'),
targetDate = new Date(countDown.data("targetdate")).getTime(),
timeDiffrence = {};
function zeroFill( number, width ) {
width -= number.toString().length;
if ( width > 0 )
{
return new Array( width + (/\./.test( number ) ? 2 : 1) ).join( '0' ) + number;
}
return number + ""; // always return a string
}
function calculateTimeDiffrence (currentDate, targetDate) {
var tmpTime = targetDate - currentDate;
console.log(targetDate + ', ' + currentDate);
console.log(tmpTime);
if (timeDiffrence) {
timeDiffrence.days = zeroFill(Math.floor(tmpTime/1000/60/60/24), 2);
tmpTime -= timeDiffrence.days*24*60*60*1000;
timeDiffrence.hours = zeroFill(Math.floor(tmpTime/1000/60/60), 2);
tmpTime -= timeDiffrence.hours*60*60*1000;
timeDiffrence.minutes = zeroFill(Math.floor(tmpTime/1000/60), 2);
tmpTime -= timeDiffrence.minutes*60*1000;
timeDiffrence.seconds = zeroFill(Math.floor(tmpTime/1000), 2);
console.log(timeDiffrence);
}
}
function updateCountDown (countDown) {
var currentDate = new Date().getTime();
console.log(currentDate);
console.log($('.countdown'));
calculateTimeDiffrence(currentDate, targetDate);
days.text(timeDiffrence.days);
hours.text(timeDiffrence.hours);
minutes.text(timeDiffrence.minutes);
seconds.text(timeDiffrence.seconds);
}
(function() {
nIntervId = setInterval(updateCountDown, 1000);
})();
</script>
</html>