-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclock.js
64 lines (42 loc) · 1.2 KB
/
clock.js
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
var Clock = (function(){
var exports = function(element) {
this._element = element;
this._slots = [];
};
exports.prototype = {
update:function(text) {
if(this._slots.length == 0) {
var html = '';
for (var i=0;i<text.length;i++) {
if(this._slots.length <= i)
html += '<span>' + text.charAt(i) + '</span>';
}
this._element.innerHTML = html;
this._slots = this._element.getElementsByTagName('span');
}
for(var i = 0; i < this._slots.length; i++) {
slot = this._slots[i];
var char = text.charAt(i);
if(char == "," || char == ".") {
char == ",";
slot.classList.add('divider');
} else {
slot.classList.remove('divider');
}
if(char == "" || !char) char = "0";
slot.dataset.old = text.charAt(i);
}
},
flip:function(slot,value) {
// setup new state
slot.classList.remove('flip');
slot.dataset.old = slot.dataset.now;
slot.dataset.now = value;
// force dom reflow
slot.offsetLeft;
// start flippin
slot.classList.add('flip');
}
};
return exports;
}());