forked from jayKayEss/Flapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.html
182 lines (162 loc) · 7.19 KB
/
test.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<!DOCTYPE html>
<html>
<head>
<title>Flip Digits</title>
<link href="css/flapper.css" type="text/css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="transform/dist/jquery.transform-0.9.3.min.js"></script>
<script src="./jquery.flapper.js"></script>
<script language="javascript">
$(document).ready(function() {
FlapDigit = function($ele) {
this.digits = [' ', 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, '.', ',', ':', '$'];
this.pos = 0;
this.target = this.digits[0];
this.interval = 150;
this.timeout;
this.animate = true;
this.$prev = $ele.find('.front.top, .back.bottom');
this.$next = $ele.find('.back.top, .front.bottom');
this.$back_top = $ele.find('.back.top');
this.$back_bottom = $ele.find('.back.bottom');
this.$front_top = $ele.find('.front.top');
this.$front_bottom = $ele.find('.front.bottom');
this.initialize();
}
FlapDigit.prototype = {
initialize: function() {
this.$prev.html(this.digits[this.pos]);
this.$next.html(this.digits[this.pos]);
console.log(this);
},
increment: function() {
var _this = this;
var next = this.pos + 1;
if (next >= this.digits.length) {
next = 0;
}
this.$prev.show().html(this.digits[this.pos]);
this.$next.hide().html(this.digits[next]);
var speed1 = Math.floor(Math.random() * this.interval * .4 + this.interval * .3);
var speed2 = Math.floor(Math.random() * this.interval * .1 + this.interval * .2);
if (this.animate) {
this.$back_top.show();
this.$front_bottom.transform({ scaleY: 0.0 });
this.$front_top.transform({ scaleY: 1.0 }).stop().show().animate({ scaleY: 0.0 }, speed1, 'swing', function(){
_this.$front_bottom.stop().show().animate({ scaleY: 1.0 }, speed2, 'linear');
});
} else {
this.$front_top.hide();
this.$back_top.show();
if (this.timeout) {
clearTimeout(this.timeout);
}
this.timeout = setTimeout(function(){
this.$back_bottom.hide();
this.$front_bottom.show();
}, speed);
}
this.pos = next;
},
cycleTo: function(pos) {
var _this = this;
if (this.interval_timer) {
clearInterval(this.interval_timer);
this.interval_timer = null;
}
this.interval_timer = setInterval(function(){
if (_this.pos == pos) {
clearInterval(_this.interval_timer);
_this.interval_timer = null;
} else {
_this.increment();
}
}, this.interval);
}
};
$('.flapper .digit').each(function() {
var flap = new FlapDigit($(this));
var rand = Math.floor(Math.random() * 9) + 1;
flap.cycleTo(rand);
setInterval(function() {
var rand = Math.floor(Math.random() * 9) + 1;
flap.cycleTo(rand);
}, 10000);
});
});
</script>
<style type="text/css">
.flapper {
margin: 20px auto;
padding: 20px;
text-align: center;
}
</style>
</head>
<body>
<div class="flapper light XXL">
<div class="digit">
<div class="back top"> </div>
<div class="back bottom"> </div>
<div class="front top"> </div>
<div class="front bottom"> </div>
</div>
<div class="digit">
<div class="back top"> </div>
<div class="back bottom"> </div>
<div class="front top"> </div>
<div class="front bottom"> </div>
</div>
<div class="digit">
<div class="back top"> </div>
<div class="back bottom"> </div>
<div class="front top"> </div>
<div class="front bottom"> </div>
</div>
<div class="digit">
<div class="back top"> </div>
<div class="back bottom"> </div>
<div class="front top"> </div>
<div class="front bottom"> </div>
</div>
<div class="digit">
<div class="back top"> </div>
<div class="back bottom"> </div>
<div class="front top"> </div>
<div class="front bottom"> </div>
</div>
</div>
<div class="flapper dark XXL">
<div class="digit">
<div class="back top"> </div>
<div class="back bottom"> </div>
<div class="front top"> </div>
<div class="front bottom"> </div>
</div>
<div class="digit">
<div class="back top"> </div>
<div class="back bottom"> </div>
<div class="front top"> </div>
<div class="front bottom"> </div>
</div>
<div class="digit">
<div class="back top"> </div>
<div class="back bottom"> </div>
<div class="front top"> </div>
<div class="front bottom"> </div>
</div>
<div class="digit">
<div class="back top"> </div>
<div class="back bottom"> </div>
<div class="front top"> </div>
<div class="front bottom"> </div>
</div>
<div class="digit">
<div class="back top"> </div>
<div class="back bottom"> </div>
<div class="front top"> </div>
<div class="front bottom"> </div>
</div>
</div>
</body>
</html>