-
Notifications
You must be signed in to change notification settings - Fork 3
/
jquery.type-char-animation.js.adhoc-test.html
169 lines (137 loc) · 3.82 KB
/
jquery.type-char-animation.js.adhoc-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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery Type Char Adhoc test</title>
<style type="text/css">
#main {
}
#textarea {
width: 45%;
height: 400px;
font-family: monospace;
}
#div {
width: 45%;
height: 400px;
float: right;
border: 1px solid black;
overflow: auto;
}
#btn-div, #btn-stop-div {
float: right;
}
fieldset {
margin-top: 1em;
}
</style>
<script>
(function (w, doc,co) {
// http://stackoverflow.com/questions/901115/get-query-string-values-in-javascript
var u = {},
e,
a = /\+/g, // Regex for replacing addition symbol with a space
r = /([^&=]+)=?([^&]*)/g,
d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
q = w.location.search.substring(1),
v = '2.1.1';
while (e = r.exec(q)) {
u[d(e[1])] = d(e[2]);
}
if (!!u.jquery) {
v = u.jquery;
}
doc.write('<script src="http://ajax.googleapis.com/ajax/libs/jquery/'+v+'/jquery.min.js">' + "<" + '/' + 'script>');
co.log('\nLoading jQuery v' + v + '\n');
})(window, document, console);
</script>
</head>
<body>
<h1>jQuery Type Char</h1>
<div id="main">
<textarea id="textarea"></textarea>
<div id="div"></div>
<button id="btn-textarea">Animate text area</button>
<button id="btn-stop-textarea">Stop</button>
<button id="btn-div">Animate div</button>
<button id="btn-stop-div">Stop</button>
<br />
<button id="btn-stop">Stop All</button>
<fieldset>
<legend>Options</legend>
<label>
<input id="chk-reverse" type="checkbox" />
Reverse animation
</label>
<label>
<input id="chk-block" type="checkbox" />
Block user input
</label>
<label>
<input id="chk-matrix" type="checkbox" />
Matrix effect
</label>
</fieldset>
</div>
<script src="../src/jquery.type-char-animation.js"></script>
<script>
(function ($) {
'use strict';
var win = $(window);
var textarea = $('#textarea');
var div = $('#div');
var btnText = $('#btn-textarea');
var btnDiv = $('#btn-div');
var chkReverse = $('#chk-reverse');
var chkBlock = $('#chk-block');
var chkMatrix = $('#chk-matrix');
var string = 'Bacon ipsum dolor sit amet chuck turkey salami, brisket prosciutto ham cow. Shank sausage boudin frankfurter pastrami beef shoulder. Pork loin pork chop pastrami jerky, drumstick ham hock turkey brisket biltong boudin t-bone ham hamburger bacon. Pork loin beef ribs venison pancetta meatball shank tongue sausage tail leberkas shoulder. Shank jowl sirloin pork chop tenderloin, corned beef beef kielbasa pig pastrami rump beef ribs.';
var isOn = function (chk) {
return !!chk.prop('checked');
};
var step = function (char, tPos) {
console.log('step #' + tPos + ' ' + char);
};
var complete = function () {
console.log('complete');
};
var stop = function (target) {
return function _stop(e) {
target.typeCharAnimation('stop', {end: true});
};
};
var btnTextAnim = function (e) {
textarea.typeCharAnimation({
initialText: 'Textarea ',
text: string,
reverse: isOn(chkReverse),
blockUserInput: isOn(chkBlock),
matrixEffect: isOn(chkMatrix) ? 3 : 0,
passes: isOn(chkMatrix) ? 2 : 0,
complete: complete,
step: step
});
};
var btnDivAnim = function (e) {
div.typeCharAnimation({
initialText: 'Div ',
text: string,
reverse: isOn(chkReverse),
blockUserInput: isOn(chkBlock),
matrixEffect: isOn(chkMatrix) ? 3 : 0,
complete: complete,
step: step
});
};
var init = function () {
btnText.click(btnTextAnim);
btnDiv.click(btnDivAnim);
$('#btn-stop-textarea').click(stop(textarea));
$('#btn-stop-div').click(stop(div));
$('#btn-stop').click(stop(textarea.add(div)));
};
$(init);
})(jQuery);
</script>
</body>
</html>