forked from Zerpyre/Counter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
102 lines (78 loc) · 2.8 KB
/
script.js
File metadata and controls
102 lines (78 loc) · 2.8 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
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
console.clear();
function CountdownTracker(label, value) {
var el = document.createElement('span');
el.className = 'flip-clock__piece';
el.innerHTML = '<b class="flip-clock__card card"><b class="card__top"></b><b class="card__bottom"></b><b class="card__back"><b class="card__bottom"></b></b></b>' +
'<span class="flip-clock__slot">' + label + '</span>';
this.el = el;
var top = el.querySelector('.card__top'),
bottom = el.querySelector('.card__bottom'),
back = el.querySelector('.card__back'),
backBottom = el.querySelector('.card__back .card__bottom');
this.update = function(val) {
val = ('0' + val).slice(-2);
if (val !== this.currentValue) {
if (this.currentValue >= 0) {
back.setAttribute('data-value', this.currentValue);
bottom.setAttribute('data-value', this.currentValue);
}
this.currentValue = val;
top.innerText = this.currentValue;
backBottom.setAttribute('data-value', this.currentValue);
this.el.classList.remove('flip');
void this.el.offsetWidth;
this.el.classList.add('flip');
}
}
this.update(value);
}
function getTimeRemaining(endtime) {
var t = Date.parse(endtime) - Date.parse(new Date());
return {
'Total': t,
'DÍAS': Math.floor(t / (1000 * 60 * 60 * 24)),
'HORAS': Math.floor((t / (1000 * 60 * 60)) % 24),
'MINUTOS': Math.floor((t / 1000 / 60) % 60),
'SEGUNDOS': Math.floor((t / 1000) % 60)
};
}
function Clock(countdown, callback) {
countdown = countdown ? new Date(Date.parse(countdown)) : false;
callback = callback || function() {};
var updateFn = countdown ? getTimeRemaining : getTime;
this.el = document.createElement('div');
this.el.className = 'flip-clock';
var trackers = {},
t = updateFn(countdown),
key, timeinterval;
for (key in t) {
if (key === 'Total') { continue; }
trackers[key] = new CountdownTracker(key, t[key]);
this.el.appendChild(trackers[key].el);
}
var i = 0;
function updateClock() {
const iframe= document.getElementById("contador");
console.log("l> iframe.contentWindow.document.body.scrollHeight");
iframe.style.height = iframe.contentWindow.document.body.scrollHeight + "px";
timeinterval = requestAnimationFrame(updateClock);
if (i++ % 10) { return; }
var t = updateFn(countdown);
if (t.Total < 0) {
cancelAnimationFrame(timeinterval);
for (key in trackers) {
trackers[key].update(0);
}
callback();
return;
}
for (key in trackers) {
trackers[key].update(t[key]);
}
}
setTimeout(updateClock, 500);
}
// Configuración de la nueva fecha límite
var deadline = new Date("2024-12-09T12:00:00");
var c = new Clock(deadline, function() { alert('EMPIEZA A EXPLORAR'); });
document.body.appendChild(c.el);