forked from stephband/jquery.event.frame
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
341 lines (282 loc) · 11.1 KB
/
index.html
File metadata and controls
341 lines (282 loc) · 11.1 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
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
<!DOCTYPE html>
<!--[if gt IE 8]><!--><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><!--<![endif]-->
<!--[if IE 8]><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" class="ie ie8"><![endif]-->
<!--[if IE 7]><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" class="ie ie7"><![endif]-->
<!--[if lte IE 6]><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" class="ie ie6"><![endif]-->
<head>
<title>events.frame</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="Site description" />
<!-- Run IE8 in Compatibility Mode --><!--[if gte IE 8]><!--meta http-equiv="X-UA-Compatible" content="IE=7"--><![endif]-->
<!-- Disable image toolbar in IE6 --><!--[if lte IE 6]><meta http-equiv="imagetoolbar" content="no" /><![endif]-->
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="http://webdev.stephband.info/css/reset.css" media="all" />
<link rel="stylesheet" type="text/css" href="http://webdev.stephband.info/css/typography.css" media="all" />
<link rel="stylesheet" type="text/css" href="http://webdev.stephband.info/css/style_light.css" media="all" />
<link rel="stylesheet" type="text/css" href="http://webdev.stephband.info/css/header_light.css" media="all" />
<style type="text/css">
h2,
h3,
h4,
p,
ul,
pre { margin: 0 7% 1em 7%; }
h3 span {
font-weight: normal;
font-size: 0.7em;
text-transform: uppercase;
}
.one,
.two { width: 40%; margin-bottom: 2em; }
.one { float: left; margin-left: 7%; }
.two { float: right; margin-right: 7%; }
#one,
#two { text-align: center; font-size: 20em; font-family: Georgia, serif; line-height: 1.2em; height: 1.4em; color: #98989f; background: #eeeef1; margin-bottom: 24px; border-radius: 0.1em; -webkit-border-radius: 0.1em; -moz-border-radius: 0.1em;}
.container { margin-left: 7%; margin-right: 7%; }
.box { float: left; margin-right: 2%; width: 15%; text-align: center; font-size: 6em; font-family: Georgia, serif; line-height: 1.2em; height: 1.4em; color: #98989f; background: #eeeef1; margin-bottom: 24px; border-radius: 0.1em; -webkit-border-radius: 0.1em; -moz-border-radius: 0.1em;}
.last { margin-right: 0; }
</style>
<script type="text/javascript">
document.documentElement.className+=' js';
</script>
</head>
<body>
<div id="header">
<a href="../../index.html"><h1>webdev.stephband.info</h1></a>
</div>
<h2>jquery.event.frame</h2>
<h3>Download <span>3KB (1KB minified)</span></h3>
<p><a href="http://github.com/stephband/jquery.event.frame/archives/master">github.com/stephband/jquery.event.frame/archives/master</a></p>
<h3>What's this, then?</h3>
<p>Provides an animation timer that fires <code>frame</code> events at bound elements. Originally developed for use in jParallax, the aim is to reduce the number of timers needed on pages that require a lot of frame-based animation. There is one central timer that starts the instant a <code>frame</code> event is bound (to any element), and stops after all events are unbound.</p>
<div class="one">
<a href="#start1"><code>.bind('frame', handler)</code></a> |
<a href="#stop1"><code>.unbind('frame')</code></a>
</div>
<div class="two">
<a href="#start2"><code>.bind('frame', handler)</code></a> |
<a href="#stop2"><code>.unbind('frame')</code></a>
</div>
<div id="one" class="one">
</div>
<div id="two" class="two">
</div>
<p style="clear: both;">Besides the usual event properties provided by jQuery, a <code>frame</code> event object has the property <code>event.frameCount</code>, which is, very simply, the frame's number, starting from 0. Unbinding all frames resets <code>frameCount</code> to 0.</p>
<p style="clear: both;">Note that in the example above, each <code>.bind</code> launches the timer at a different speed. Speed can be set by passing a data object with the property <code>frameDuration: Int</code> into the <code>.bind</code>. The default is 40 (25 frames/second), but I made this demo go a lot slower than that so you can see what is going on:</p>
<pre>jQuery('.box').bind('frame', {frameDuration: 600}, fn)</pre>
<h3>Namespaced frame events</h3>
<p><strong>New in 1.1 ></strong> Each new namespace bound with a <code>frame.namespace</code> event now creates its own timer. This allows, as an example, <code>frame</code> events from different plugins to run at different rates. Click on the boxes to see what I mean...</p>
<div class="container">
<div class="box red"></div>
<div class="box red"></div>
<div class="box blue"></div>
<div class="box blue"></div>
<div class="box green"></div>
<div class="box redandgreen last"></div>
</div>
<p>Currently multiple namespaced <code>frame</code> events are not supported.</p>
<!--h3>History</h3>
<h4>1.1</h4>
<ul>
<li>Added support for namespaced timers: each bound namespace now sporks its own timer. Does not support multiple namespaces.</li>
<li>Code re-factored</li>
</ul>
<h4>1.0</h4>
<ul>
<li>First release</li>
</ul-->
<h3>Projects using jquery.event.frame</h3>
<ul>
<li><a href="http://webdev.stephband.info/jparallax/">jParallax</a> (from version 1.0)</li>
</ul>
<h3>Reporting problems</h3>
<p>Please use the issue tracker at GitHub:</p>
<p><a href="http://github.com/stephband/jquery.event.frame/issues">github.com/stephband/jquery.event.frame/issues</a></p>
<script src="../../js/jquery-1.4a1.js" type="text/javascript"></script>
<script src="js/jquery.event.frame.js" type="text/javascript"></script>
<script type="text/javascript">
function handle(e){
e.data.elem.html(e.frameCount);
}
jQuery(document).ready(function(){
var one = jQuery("#one"),
two = jQuery("#two");
jQuery("a[href='#start1']")
.bind('click', function(e){
one.bind('frame', {elem: one, frameDuration: 600}, handle);
});
jQuery("a[href='#stop1']")
.bind('click', function(e){
one
.unbind('frame')
.html('');
});
jQuery("a[href='#start2']")
.bind('click', function(e){
two.bind('frame', {elem: two, frameDuration: 300}, handle);
});
jQuery("a[href='#stop2']")
.bind('click', function(e){
two
.unbind('frame')
.html('');
});
jQuery('.box.red')
.toggle(function(e){
var elem = jQuery(this);
elem
.bind('frame.red', {frameDuration: 500}, function(e){
jQuery(this)
.html( e.frameCount )
.css({
background: '#d9cac1',
color: '#a38472',
opacity: 1
})
.stop()
.animate({
opacity: 0
}, {
duration: 500
})
});
}, function(e){
var elem = jQuery(this);
elem
.unbind('frame.red')
.stop()
.css({
background: '#eeeef1',
opacity: 1
})
.html('');
});
jQuery('.box.blue')
.toggle(function(e){
var elem = jQuery(this);
elem
.bind('frame.blue', {frameDuration: 750}, function(e){
jQuery(this)
.html( e.frameCount )
.css({
background: '#bcc9d6',
color: '#7d91a4',
opacity: 1
})
.stop()
.animate({
opacity: 0
}, {
duration: 750
})
});
}, function(e){
var elem = jQuery(this);
elem
.unbind('frame.blue')
.stop()
.css({
background: '#eeeef1',
opacity: 1
})
.html('');
});
jQuery('.box.green')
.toggle(function(e){
var elem = jQuery(this);
elem
.bind('frame.green', {frameDuration: 1000}, function(e){
jQuery(this)
.html( e.frameCount )
.css({
background: '#cbd6bc',
color: '#a1ad8f',
opacity: 1
})
.stop()
.animate({
opacity: 0
}, {
duration: 750
});
});
//.bind('frame.red', {frameDuration: 700}, function(e){
//
// jQuery(this)
// .html( e.frameCount + 'r' )
// .css({
// background: '#d9cac1',
// color: '#a38472',
// opacity: 1
// })
// .stop()
// .animate({
// opacity: 0
// }, {
// duration: 750
// });
//
//});
}, function(e){
var elem = jQuery(this);
elem
.unbind('frame')
.stop()
.css({
background: '#eeeef1',
opacity: 1
})
.html('');
});
jQuery('.box.redandgreen')
.toggle(function(e){
var elem = jQuery(this);
elem.bind('click', function(e){ console.log('pheeuwee'); });
elem
.bind('frame.green', {frameDuration: 1000}, function(e){
console.log('green handler '+e.frameCount);
jQuery(this)
.html( e.frameCount )
.css({
background: '#cbd6bc',
color: '#a1ad8f',
opacity: 1
})
.stop()
.animate({
opacity: 0
}, {
duration: 750
});
})
.bind('frame.red', {frameDuration: 700}, function(e){
console.log('red handler '+e.frameCount);
jQuery(this)
.html( e.frameCount )
.css({
background: '#d9cac1',
color: '#a38472',
opacity: 1
})
.stop()
.animate({
opacity: 0
}, {
duration: 750
});
});
}, function(e){
var elem = jQuery(this);
elem
.unbind('frame.red')
.stop()
.css({
background: '#eeeef1',
opacity: 1
})
.html('');
});
});
</script>
</body>
</html>