forked from CSS-Tricks/AnythingZoomer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
use.html
506 lines (408 loc) · 21.4 KB
/
use.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
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Anything Zoomer | Usage</title>
<link href="http://fonts.googleapis.com/css?family=Merienda+One" rel="stylesheet">
<link rel="stylesheet" href="demo/style.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script src="demo/page.js"></script>
<!-- Syntax highlighting -->
<script src="http://mottie.github.com/tablesorter/docs/js/chili/jquery.chili-2.2.js"></script>
<script src="http://mottie.github.com/tablesorter/docs/js/chili/recipes.js"></script>
</head>
<body id="use">
<div id="main-content">
<h1 id="top">AnythingZoomer<sup>2</sup></h1>
<a href="https://github.com/CSS-Tricks/AnythingZoomer/zipball/master" id="dl">Download</a>
<ul id="nav">
<li><a href="index.html">Calendar</a></li>
<li><a href="image.html">Image</a></li>
<li><a href="swap.html">Swap</a></li>
<li><a href="text.html">Text</a></li>
<li><a href="double.html">Double</a></li>
<li><a class="current" class="use" href="use.html">Usage</a></li>
<li><a class="play" href="http://jsfiddle.net/Mottie/6sp2b/">Playground</a></li>
<li><a class="issue" href="https://github.com/CSS-Tricks/AnythingZoomer/issues">Issues</a></li>
</ul>
<p class="sections">Sections: <a href="#basics">Basics</a> | <a href="#html">HTML</a> | <a href="#css">CSS</a> |
<a href="#parameters">Parameters</a> | <a href="#methods">Methods</a> | <a href="#callbacks">Callbacks</a>
<a id="to-top" href="#top" title="back to the top">^</a>
<h2 id="basics">Basics</h2>
<p>This is a jQuery plugin, so you'll need to load the jQuery library first, then the plugin file, then invoke the
new function on the area you wish to have zooming. There is a specific HTML structure and some required CSS to have all this
work correctly, so read on. The full list of parameters is also below.</p>
<pre class="html"><link rel="stylesheet" href="css/anythingzoomer.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script src="js/jquery.anythingzoomer.js"></script>
<script>
$(function(){
$("#zoom").anythingZoomer();
});
</script>
</pre>
<small>* The minimum supported jQuery version is 1.3.2.</small>
<h2 id="html">The HTML</h2>
<p>The only required HTML is the wrapper and the small area. The large area is required if you don't clone the small area.</p>
<pre><code><span class="cc c-wrap"></span><div id="zoom">
<span class="cc c-small"></span> <div class="small">
<span class="cc c-small"></span> <img src="demo/rushmore_small.jpg" alt="small rushmore" />
<span class="cc c-small"></span> </div>
<span class="cc c-commt"></span> <span class="c-commt2"><-- the large content can be cloned from the small content --></span>
<span class="cc c-large"></span> <div class="large">
<span class="cc c-large"></span> <img src="demo/rushmore.jpg" alt="big rushmore" />
<span class="cc c-large"></span> </div>
<span class="cc c-wrap"></span></div></code></pre>
<p>There are five parts to the actual zoomable area. The idea is to allow for a good amount of flexibility in customizing each part. This
includes the "small" area having different content from the "large" zooming area.</p>
<ul>
<li><span class="cc c-wrap"></span>The Wrap (#zoom) - goes around everything.</li>
<li><span class="cc c-ovrly"></span>Overlay (.az-overlay) - small image overlay; the "az-overlay" class is only applied when hovering.</li>
<li><span class="cc c-small"></span>Small Area (.small) - the default viewable area, that you mouse over to zoom.</li>
<li><span class="cc c-large"></span>Large (.large) - the content that is viewable through the zoomer.</li>
<li><span class="cc c-zoom"></span>Zoom (.az-zoom) - the zooming box that follows the mouse around.</li>
</ul>
<p>This is the HTML after the plugin has been applied.</p>
<pre><code><span class="cc c-wrap"></span><div id="zoom" class="az-wrap">
<span class="cc c-wrap"></span> <span class="az-wrap-inner">
<span class="cc c-small"></span> <div class="small az-small">
<span class="cc c-ovrly"></span> <div class="az-overly az-overlay"></div>
<span class="cc c-small"></span> <span class="az-small-inner">
<span class="cc c-small"></span> <img src="demo/rushmore_small.jpg" alt="small rushmore">
<span class="cc c-small"></span> </span>
<span class="cc c-small"></span> </div>
<span class="cc c-zoom" ></span> <div class="az-zoom az-windowed">
<span class="cc c-large"></span> <div class="large az-large">
<span class="cc c-large"></span> <img src="demo/rushmore.jpg" alt="big rushmore">
<span class="cc c-large"></span> </div>
<span class="cc c-zoom" ></span> </div>
<span class="cc c-wrap"></span> </span>
<span class="cc c-wrap"></span></div></code></pre>
<h2 id="css">The CSS</h2>
<p>The widths, heights, borders and things like that can be altered to your needs. The positioning, z-index, overflow, and top/left values should stay as it is here to function properly.</p>
<h3>Image Demo CSS Example</h3>
<pre class="css">.zoom { width: 500px; }
.small img { width: 250px; height: 167px; }
.large img { width: 500px; height: 333px; background: white; }</pre>
<h3>anythingzoomer.css</h3>
<pre class="css">/* AnythingZoomer */
.az-wrap, .az-small, .az-large {
position: relative;
}
.az-wrap-inner {
display: block;
margin: 0 auto; /* center small & large content */
}
/* This wraps the large image and hides it */
.az-zoom {
background: #fff;
border: #333 1px solid;
position: absolute;
top: 0;
left: 0;
width: 110px;
height: 110px;
overflow: hidden;
z-index: 100;
display: none;
-moz-box-shadow: inset 0px 0px 4px #000;
-webkit-box-shadow: inset 0px 0px 4px #000;
box-shadow: inset 0px 0px 4px #000;
}
/* Class applied to az-mover when large image is windowed */
.az-windowed {
overflow: hidden;
position: absolute;
}
/* Class applied to az-mover when large image is fully shown */
.az-expanded {
height: auto;
width: auto;
position: static;
overflow: visible;
}
/* overlay small area */
.az-overlay {
background-color: #000;
opacity: 0.3;
filter: alpha(opacity=30);
z-index: 10;
}
/* fade out small content when hovering
.az-hovered > * {
opacity: 0.5;
filter: alpha(opacity=50);
}
*/
/* edit mode coordinate styling */
.az-coords {
display: none; /* hidden when expanded */
}
.az-zoom .az-coords {
display: block;
position: absolute;
top: 0;
right: 0;
background: #000;
background: rgba(0,0,0,0.5);
color: #fff;
}</pre>
<h2 id="parameters">All Parameters</h2>
<pre class="js">$("#zoom").anythingZoomer({
// content areas
smallArea : 'small', // class of small content area; the element with this class name must be inside of the wrapper
largeArea : 'large', // class of large content area; this class must exist inside of the wrapper. When the clone option is true, it will add this automatically
clone : false, // Make a clone of the small content area, use css to modify the style
// appearance
overlay : false, // set to true to apply overlay class "az-overlay"; false to not apply it
speed : 100, // fade animation speed (in milliseconds)
edge : 30, // How far outside the wrapped edges the mouse can go; previously called "expansionSize"
offsetX : 0, // adjust the horizontal position of the large content inside the zoom window as desired
offsetY : 0, // adjust the vertical position of the large content inside the zoom window as desired
// functionality
switchEvent : 'dblclick', // event that allows toggling between small and large elements - default is double click
delay : 0, // time to delay before revealing the zoom window
// edit mode
edit : false, // add x,y coordinates into zoom window to make it easier to find coordinates
// callbacks
initialzied : function(event, zoomer){}, // AnythingZoomer done initializing
zoom : function(event, zoomer){}, // zoom window visible
unzoom : function(event, zoomer){} // zoom window hidden
});</pre>
<div class="info">
<h4>smallArea</h4>
<ul>
<li>Class name given to the small content area.</li>
<li>This element must be inside of the wrapper and should contain an image or whatever visible content the user hovers over.</li>
<li>Default value is <code>'small'</code>.</li>
</ul>
<h4>largeArea</h4>
<ul>
<li>Class name given to the large content area.</li>
<li>This element must be inside of the wrapper and should contain an image or whatever visible content that will be seen inside the zoom window.</li>
<li>The large content is replaced by a clone of the small area when the clone option is true. The dimensions of the large content should be set in the css.</li>
<li>Default value is <code>'large'</code>.</li>
</ul>
<h4>clone</h4>
<ul>
<li>Make a clone of the small content and add it to the large area.</li>
<li>This option allows you to only need to add the content to the page once, if the only difference between the small and large content is the dimensions defined by the css.</li>
<li>See the <a href="text.html">text demo</a> for an example of how this can be useful.</li>
<li>Default value is <code>false</code>.</li>
</ul>
<h4>overlay</h4>
<ul>
<li>An overlay is automatically added over every small content area. When this option is true, the overlay element will get a class name of "az-overlay" added to it.</li>
<li>The css definition for "az-overlay" is within the "anythingzoomer.css" file and can be used to darken the small content during hovering (see the <a href="image.html">image demo</a>). Alternatively, you can lighten the small area content (look in the anythingzoomer.css file for the commented out definition for ".az-hovered > *") by using the hover class name (not associated with this option).</li>
<li>Default value is <code>false</code>.</li>
</ul>
<h4>speed</h4>
<ul>
<li>Change the animation speed (in milliseconds) of the zoom window fading in and out.</li>
<li>Default value is <code>100</code>.</li>
</ul>
<h4>edge</h4>
<ul>
<li>This sets the number of pixels from the outside edge of the small content to maintain the zoom window. Or, said another way... when the mouse arrow is beyond the small content edge by this set number of pixel, the zoom window will fade out.</li>
<li>The small content edge may vary slightly depending on the value of the content ratio between the small and large content. See a more detailed explanation in the <code>offsetX</code> section below.</li>
<li>Default value is <code>30</code>.</li>
</ul>
<h4>offsetX & offsetY</h4>
<ul>
<li>When using the <code>edit</code> option, you may sometimes notice that the top left corner of the image isn't at 0,0 and the bottom right corner doesn't match the small area dimensions like it should be. This is partially due to the jQuery offset not including borders, margins or padding. And partially due to the ratio between the small and large areas .</li>
<li>Sometimes it isn't a big deal to be a few pixels off, but if you need to adjust it perfectly, use these options. To do this, enable the edit mode coordinates (set edit to true) then use these options to adjust the location of the large content within the zoom window to set the proper position.</li>
<li>Default value is <code>0</code>.</li>
</ul>
<h4>switchEvent</h4>
<ul>
<li>This is the name of the event that allows toggling between the small and large content.</li>
<li>Valid events include: "click", "dblclick", "mouseover", "mouseout", etc.</li>
<li>Default value is <code>dblclick</code>.</li>
</ul>
<h4>delay</h4>
<ul>
<li>Time to delay (in milliseconds) before revealing the zoom window.</li>
<li>This is useful if you don't want the zoom window to open when the user is quickly passing over the content.</li>
<li>Default value is <code>0</code>.</li>
</ul>
<h4>edit</h4>
<ul>
<li>When true, this option will add x,y coordinates into zoom window to make it easier to find coordinates.</li>
<li>This is useful if you plan on using external triggers to open a zoom window. See the <a href="#methods">Methods</a> section below.</li>
<li>Default value is <code>false</code>.</li>
</ul>
<h4>initialized</h4>
<ul>
<li>This is an optional callback function which is executed after AnythingZoomer has completely set up.</li>
<li>Add any custom function using the <code>event</code> or <code>zoomer</code> object as desired.</li>
<li>For a list of <code>zoomer</code> arguments and functions, see the <a href="#arguments">callback arguments</a> section below.</li>
<li>Default value is <code>undefined</code>.</li>
</ul>
<h4>zoom</h4>
<ul>
<li>This is an optional callback function which is executed after the AnythingZoomer zoom window becomes visible.</li>
<li>Add any custom function using the <code>event</code> or <code>zoomer</code> object as desired.</li>
<li>For a list of <code>zoomer</code> arguments and functions, see the <a href="#arguments">callback arguments</a> section below.</li>
<li>Default value is <code>undefined</code>.</li>
</ul>
<h4>unzoom</h4>
<ul>
<li>This is an optional callback function which is executed after the AnythingZoomer zoom window has hidden.</li>
<li>Add any custom function using the <code>event</code> or <code>zoomer</code> object as desired.</li>
<li>For a list of <code>zoomer</code> arguments and functions, see the <a href="#arguments">callback arguments</a> section below.</li>
<li>Default value is <code>undefined</code>.</li>
</ul>
</div>
<h2 id="methods">Methods</h2>
<h3>Enable or Disable AnythingZoomer</h3>
<p>To enable or disable AnythingZoomer, call the plugin with the appropriate text:</p>
<pre class="js">$('.zoom').anythingZoomer('disable'); // disable AnythingZoomer
$('.zoom').anythingZoomer('enable'); // enable AnythingZoomer</pre>
<p>This method is demonstrated in the <a href="double.html">Double</a> demo page. What isn't shown there is that when AnythingZoomer is disabled, the zoom window automatically closes and the small area content is shown.</p>
<h3>Control Zoom Window Externally</h3>
<p>You can open the zoom window using an external link using these methods. This would be useful to highlight portions of the content in say instructions on how to use an app or name the presidents in the image demo.</p>
<pre class="js">// TARGET X,Y COORDINATE
// $('.zoom').anythingZoomer( x, y, [ w, h ] );
// x, y = left and top coords to target (will be centered in the zoom window)
// w, h = width and height of the zoom window, if not defined, it will default to the css definition
// Example: $('.zoom').anythingZoomer( 88, 51, [200,200] );
// 88, 51 will target George Washington; [200,200] will make the zoom window 200px x 200px in size
$('.zoom').anythingZoomer( 88, 51, [200,200] );
// TARGET AN OBJECT
// $('.zoom').anythingZoomer( 'selector', [ xOffset, yOffset ], [zoomW, zoomH] );
// 'selector' - jQuery selector targeting the element
// [xOffset, yOffset] - by default the zoom window will center itself on the element, if you want to move the window, change the offset values (negative values are okay)
// [zoomW, zoomH] - width and height of the zoom window
// Example: $('.zoom').anythingZoomer( '.day[rel=2009-08-26]', [0, 0], [200, 200] );
// '.day[rel=2009-08-26]' targets the table cell with day class name and rel attribute of "2009-08-26"
// [ 0, 0 ] has no x or y offset; this can be replaced with '' (empty string); or if only one number is included, like [-1] this sets the xOffset only
// [200,200] will make the zoom window 200px x 200px in size
$('.zoom').anythingZoomer( '.day[rel=2009-08-26]', [0, 0], [200, 200] );
</pre>
<h3>Image Demo Example</h3>
<pre class="html"><a href="#" class="president" rel="88,51">George Washington</a>,
<a href="#" class="president" rel="114,62">Thomas Jefferson</a>,
<a href="#" class="president" rel="133,80">Theodore Roosevelt</a> or
<a href="#" class="president" rel="160,78">Abraham Lincoln</a></pre>
<pre class="js">$('.president')
// prevent the link from doing anything
.bind('click', function(){
return false;
})
// click or mouseover the link to show the zoom window
.bind('mouseover click', function(){
// get coordinates from rel attribute
var loc = $(this).attr('rel');
if (loc && loc.indexOf(',') > 0) {
loc = loc.split(',');
// send the coordinates to anythingZoomer
$('.zoom').anythingZoomer( loc[0], loc[1] );
}
return false;
});</pre>
<h2 id="callbacks">Callbacks and Events</h2>
<p>These callbacks were added to allow further customizations.</p>
<h3>Callback functions</h3>
<pre class="js">$('#zoom').anythingZoomer({
// initialized occurs after AnythingZoomer has initialized
initialized : function(e, zoomer){},
// zoom occurs when the zoom window is visible
zoom : function(e, zoomer){},
// unzoom occurs when the zoom window is hidden
unzoom : function(e, zoomer){}
});
</pre>
<h3>Events</h3>
<p>Bind to the AnythingZoomer's events as follows:</p>
<pre class="js">
$('#zoom').bind('initialized', function(e, zoomer){
// do something after AnythingZoomer has initialized
});
$('#zoom').bind('zoom unzoom', function(e, zoomer){
// do something when the zoom toggles
if (e.type === "zoom") {
// do something when zoomed
} else {
// do something when unzoomed
}
});</pre>
<h3 id="arguments">Callback and Events Arguments and Functions</h3>
<p>These arguments and functions are available from the callback or event methods, or from the <code>zoomer</code> data object.
<br>Access the AnythingZoomer object from outside of callbacks and events as follows:</p>
<pre class="js">var zoomer = $('#zoom').data('zoomer');</pre>
<div class="info">
<h4>zoomer.$wrap</h4>
<ul>
<li>jQuery object of the wrapper which contains both the large and small content.</li>
</ul>
<h4>zoomer.state</h4>
<ul>
<li>true when the small content is showing, false when large content is visible.</li>
</ul>
<h4>zoomer.current</h4>
<ul>
<li>This variable contains the current x and y position of the mouse within the small content area.</li>
<li>The value is updated everytime the mouse is moved, so it can be monitored externally if desired.</li>
</ul>
<h4>zoomer.$inner</h4>
<ul>
<li>jQuery object of the span immediately inside of <code>zoomer.$wrap</code>.</li>
<li>This is the element that centers the small and large content using css; look in <code>.az-wrap-inner</code>.</li>
</ul>
<h4>zoomer.$small</h4>
<ul>
<li>jQuery object of the small area.</li>
</ul>
<h4>zoomer.$large</h4>
<ul>
<li>jQuery object of the large area.</li>
</ul>
<h4>zoomer.$zoom</h4>
<ul>
<li>jQuery object of the zoom window which contains the large content area.</li>
<li>This is the zoom window that follows the mouse and repositions the large area.</li>
</ul>
<h4>zoomer.$overlay</h4>
<ul>
<li>jQuery object of the overlay element which is contained within the small area and has the same dimensions.</li>
<li>When the <code>overlay</code> option is true, this object gets the <code>az-overlay</code> class name applied to it.</li>
</ul>
<h4>zoomer.options.{name}</h4>
<ul>
<li>Access any of the zoomer options (e.g. <code>zoomer.options.edge</code>).</li>
<li>Trying to set the options this way is possible, but may break the zoomer.</li>
</ul>
<h4>zoomer.setTarget('selector', [xOffset, yOffset], [zoomW, zoomH])</h4>
<ul>
<li>This function is called when controlling the zoom window externally.</li>
<li>Call this function if you are using a jQuery selector to target an element; use <code>zoomer.zoomAt()</code> if you have specific coordinates to set.</li>
<li>Please refer to the methods section for more details on how to set the parameters.</li>
</ul>
<h4>zoomer.zoomAt(x, y, [zoomW, zoomH])</h4>
<ul>
<li>This function is called by the <code>zoomer.setTarget()</code> function after it calculates the x and y coordinates.</li>
<li>Call this function directly if you already know the coordinates.</li>
</ul>
<h4>zoomer.showSmall()</h4>
<ul>
<li>This function is called when switching from the large content to the small content.</li>
</ul>
<h4>zoomer.showLarge()</h4>
<ul>
<li>This function is called when switching from the small to large content.</li>
</ul>
<h4>zoomer.hideZoom()</h4>
<ul>
<li>This function is called when the zoom window needs to be hidden.</li>
<li>The "unzoom" callback will not be triggered.</li>
</ul>
<h4>zoomer.setEnabled(boolean)</h4>
<ul>
<li>This function will enable (if boolean is true) or disable (if boolean is false) AnythingZoomer.</li>
<li>When the plugin is disabled, any open zoom window will be closed and the large content will be hidden.</li>
<li>This function is called directly from the shortcut method which allows you to call the plugin using 'enable' or 'disable'.</li>
</ul>
</div>
</div>
</body>
</html>