forked from desandro/masonry
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
executable file
·310 lines (221 loc) · 14.9 KB
/
index.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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>jQuery Masonry › Primer</title>
<link rel="stylesheet" type="text/css" href="css/masonry_example.css" media="screen" charset="utf-8" />
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery.masonry.js"></script>
</head>
<body>
<ol id="nav">
<li><strong>jQuery Masonry ›</strong></li>
<li class="selected"><a href=".">Primer</a></li>
<li><a href="basic.html">Basic Examples</a></li>
<li><a href="tumblelog.html">Tumblelog Example</a></li>
<li><a href="infinite_scroll.html">Infinite Scroll Example</a></li>
</ol>
<h1>Primer</h1>
<div class="copy">
<p>Masonry is a layout plugin for jQuery. Think of it as the flip side of CSS floats. Whereas floating arranges elements horizontally then vertically, Masonry arranges elements vertically then horizontally according to a grid. The result minimizes vertical gaps between elements of varying height, just like a mason fitting stones in a wall.</p>
</div><!-- .copy -->
<div id="comparison">
<h2>Comparison Example</h2>
<div class="example">
<h3>CSS Floats</h3>
<div id="primary" class="wrap">
<div class="box col1">
<h5>1</h5>
<p>Donec nec justo eget felis facilisis fermentum. Aliquam porttitor mauris. </p>
</div>
<div class="box col2">
<h5>2</h5>
<p>Nullam malesuada erat ut turpis. Suspendisse urna nibh, viverra non, semper suscipit.</p>
</div>
<div class="box col1">
<h5>3</h5>
<p>Fusce accumsan mollis eros. Pellentesque a diam sit amet mi ullamcorper vehicula. Ut eget sem risus, et posuere velit. Aenean ac mauris non ligula. </p>
</div>
<div class="box col1">
<h5>4</h5>
<p>Morbi purus libero, faucibus adipiscing, commodo quis, gravida id, est. Sed lectus.</p>
</div>
<div class="box col1">
<h5>5</h5>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec odio.</p>
</div>
<div class="box col1">
<h5>6</h5>
<p>Cadipiscing in, lacinia vel, tellus. </p>
</div>
<div class="box col1">
<h5>7</h5>
<p>Pellentesque a diam sit amet mi ullamcorper vehicula. adipiscing in, lacinia vel, tellus.</p>
</div>
<div class="box col3">
<h5>8</h5>
<p>Sed ac risus. Phasellus lacinia, magna a ullamcorper laoreet, lectus arcu pulvinar risus, vitae facilisis libero dolor a purus. Suspendisse ac urna. Etiam pellentesque. Sed vel lacus. Mauris nibh felis, adipiscing varius, adipiscing in, lacinia vel, tellus. Suspendisse ac urna. Etiam pellentesque mauris ut lectus. Nunc tellus ante, mattis eget, gravida vitae, ultricies ac, leo. Integer leo pede, ornare a, lacinia eu, vulputate vel, nisl. Suspendisse ac urna. Etiam pellentesque. </p>
</div>
<div class="box col2">
<h5>9</h5>
<p>Ut convallis, sem sit amet interdum consectetuer, odio augue aliquam leo, nec dapibus tortor nibh sed augue. Ut condimentum mi vel tellus. Suspendisse laoreet. Fusce ut est sed dolor gravida convallis. Morbi vitae ante. Vivamus ultrices luctus nunc. Suspendisse et dolor. Pellentesque a diam sit amet mi ullamcorper vehicula. adipiscing in, lacinia vel, tellus.</p>
</div>
<div class="box col1">
<h5>10</h5>
<p>Etiam pellen tesque mauris ut lectus.</p>
</div>
<div class="box col1">
<h5>11</h5>
<p>Mauris nibh felis, adipiscing varius, adipiscing in, lacinia vel, tellus. Suspen disse ac urna. Ut condi mentum mi vel tellus.</p>
</div>
<div class="box col1">
<h5>12</h5>
<p>Phasellus pede arcu, dapibus eu, fermentum et, dapibus sed, urna.</p>
</div>
</div> <!-- /#primary.wrap -->
</div>
<div class="example">
<h3>Masonry</h3>
<div id="secondary" class="wrap">
<div class="box col1">
<h5>1</h5>
<p>Donec nec justo eget felis facilisis fermentum. Aliquam porttitor mauris. </p>
</div>
<div class="box col2">
<h5>2</h5>
<p>Nullam malesuada erat ut turpis. Suspendisse urna nibh, viverra non, semper suscipit.</p>
</div>
<div class="box col1">
<h5>3</h5>
<p>Fusce accumsan mollis eros. Pellentesque a diam sit amet mi ullamcorper vehicula. Ut eget sem risus, et posuere velit. Aenean ac mauris non ligula. </p>
</div>
<div class="box col1">
<h5>4</h5>
<p>Morbi purus libero, faucibus adipiscing, commodo quis, gravida id, est. Sed lectus.</p>
</div>
<div class="box col1">
<h5>5</h5>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec odio.</p>
</div>
<div class="box col1">
<h5>6</h5>
<p>Cadipiscing in, lacinia vel, tellus. </p>
</div>
<div class="box col1">
<h5>7</h5>
<p>Pellentesque a diam sit amet mi ullamcorper vehicula. adipiscing in, lacinia vel, tellus.</p>
</div>
<div class="box col3">
<h5>8</h5>
<p>Sed ac risus. Phasellus lacinia, magna a ullamcorper laoreet, lectus arcu pulvinar risus, vitae facilisis libero dolor a purus. Suspendisse ac urna. Etiam pellentesque. Sed vel lacus. Mauris nibh felis, adipiscing varius, adipiscing in, lacinia vel, tellus. Suspendisse ac urna. Etiam pellentesque mauris ut lectus. Nunc tellus ante, mattis eget, gravida vitae, ultricies ac, leo. Integer leo pede, ornare a, lacinia eu, vulputate vel, nisl. Suspendisse ac urna. Etiam pellentesque. </p>
</div>
<div class="box col2">
<h5>9</h5>
<p>Ut convallis, sem sit amet interdum consectetuer, odio augue aliquam leo, nec dapibus tortor nibh sed augue. Ut condimentum mi vel tellus. Suspendisse laoreet. Fusce ut est sed dolor gravida convallis. Morbi vitae ante. Vivamus ultrices luctus nunc. Suspendisse et dolor. Pellentesque a diam sit amet mi ullamcorper vehicula. adipiscing in, lacinia vel, tellus.</p>
</div>
<div class="box col1">
<h5>10</h5>
<p>Etiam pellen tesque mauris ut lectus.</p>
</div>
<div class="box col1">
<h5>11</h5>
<p>Mauris nibh felis, adipiscing varius, adipiscing in, lacinia vel, tellus. Suspen disse ac urna. Ut condi mentum mi vel tellus.</p>
</div>
<div class="box col1">
<h5>12</h5>
<p>Phasellus pede arcu, dapibus eu, fermentum et, dapibus sed, urna.</p>
</div>
</div> <!-- /#secondary.wrap -->
</div>
</div>
<div class="copy">
<h2>Minimum recommended configuration</h2>
<p>Configuring Masonry is fairly easy. Simply attach the <code>.masonry()</code> method to the wrapping container element. Depending on the layout, you’ll most likely need to specify one option.</p>
<p>For layouts with elements that span multiple widths:</p>
<pre><code><span class="keyword">$</span>(<span class="string">'#wrapper'</span>).masonry({ columnWidth: <span class="constant">200</span> });</code></pre>
<p>For layouts with elements that span the same width:</p>
<pre><code><span class="keyword">$</span>(<span class="string">'#wrapper'</span>).masonry({ singleMode: <span class="constant">true</span> });</code></pre>
<h2>All options</h2>
<pre><code><span class="keyword">$</span>(<span class="string">'#wrapper'</span>).masonry({
singleMode: <span class="constant">false</span>,
<span class="comment">// Disables measuring the width of each floated element.
// Set to true if floated elements have the same width.
// default: false</span>
columnWidth: <span class="constant">240</span>,
<span class="comment">// Width in pixels of 1 column of your grid.
// default: outer width of the first floated element.</span>
itemSelector: <span class="string">'.box:visible'</span>,
<span class="comment">// Additional selector to specify which elements inside
// the wrapping element will be rearranged.
// Required for Infinite Scroll with window resizing.</span>
resizeable: <span class="constant">true</span>,
<span class="comment">// Binds a Masonry call to window resizes.
// default: true</span>
appendedContent: <span class="keyword">$</span>(<span class="string">'.new_content'</span>),
<span class="comment">// Additional container element for appended content.
// Useful for Infinite Scroll integration.</span>
saveOptions: <span class="constant">true</span>,
<span class="comment">// Masonry will use the options from previous Masonry
// calls by default, so you only have to enter in options once
// default: true</span>
}, <span class="storage">function</span>() {}
<span class="comment">// Optional callback.
// 'this' will refer to the applicable elements Masonry just rearranged</span>
);</code></pre>
<p>No need to worry about how many columns, or width of gutters, or how big the container is. Thanks to the wonders of jQuery’s <code>outerWidth()</code> and <code>innerWidth()</code> methods, Masonry appropriately accounts for the space of any margin, padding, and border-width set with CSS. </p>
<h2>Window Resizing</h2>
<p>By default, Masonry binds a call to the browser window for resizing. But the rearrangement script is triggered only when the layout adds or loses a column, so you don’t have to worry about Masonry slowing down window resizes, or with fixed layouts.</p>
<h2>Handling Images</h2>
<p>Since Masonry measures the height of the elements when placing them, you will need to account for images that haven't loaded. The best method is to specify the width and height of images inline.</p>
<pre><code><span class="storage"><img src=<span class="string">"img_file.jpg"</span> <span class="string">width="280"</span> <span class="string">height="160"</span> /></span></code></pre>
<p>If you’re using a PHP-based CMS, you can use the <a href="http://php.net/manual/en/function.getimagesize.php">getimagesize</a> function.</p>
<p>If this is not possible, another option is to call Masonry after all the images have loaded. This is done by calling the function inside of <code>$(window).load()</code> instead of <code>$(document).ready()</code>.</p>
<pre><code><span class="keyword">$</span>(<span class="string">'window'</span>).<span class="keyword">load</span>(<span class="storage">function</span>(){
<span class="keyword">$</span>(<span class="string">'#wrapper'</span>).masonry({ columnWidth: <span class="constant">200</span> });
});</code></pre>
<h2>Resolving Anchor Links</h2>
<p>Since Masonry relies on absolute positioning, any anchor links that occur within or after the wrapping element will not work when the page first loads. The following script is one solution.</p>
<pre><code><span class="keyword">$</span>(<span class="string">'window'</span>).<span class="keyword">load</span>(<span class="storage">function</span>(){
<span class="keyword">if</span> ( <span class="keyword">window</span>.<span class="keyword">location</span>.<span class="keyword">hash</span> ) {
<span class="storage">var</span> destination = <span class="keyword">$</span>( <span class="keyword">window</span>.<span class="keyword">location</span>.<span class="keyword">hash</span> ).offset().<span class="keyword">top</span>;
<span class="keyword">$</span>(<span class="string">'html:not(:animated),body:not(:animated)'</span>).scrollTop( destination );
}
});</code></pre>
<p>This will set the window of the document to the appropriate place. These couple lines were taken from <a href="http://blog.position-absolute.com/javascript-jquery/the-end-of-the-html-anchor-scroll-the-scroll/">Cedric Dugas’s anchorAnything.</a></p>
<h2>Examples in the Wild</h2>
<ul id="inthewild">
<li><a href="http://www.tumblr.com/theme/3531">Astronaut Tumblr Theme by Peter Vidani</a></li>
<li><a href="http://www.woothemes.com/demo/?t=41">Mortar WordPress Theme by WooThemes</a></li>
<li><a href="http://maxvoltar.com">Maxvoltar</a></li>
<li><a href="http://www.mrbridge.co.nz/fluidadvert.html">Andy Bridge</a></li>
<li><a href="http://chromeography.com">Chromeography</a></li>
<li><a href="http://jquerystyle.com">jQuery Style</a></li>
</ul>
<h2>Changelog</h2>
<dl>
<dt>v1.0.1: 19 Dec 2009</dt>
<dd>Bug fix, checks that container element exists and has children before running the script.</dd>
<dt>v1.0: 7 Dec 2009</dt>
<dd>Multi-column width support</dd>
<dd>Appending elements and Infinite Scroll support</dd>
<dd>Less obstrusive layout. No inserting additional markup.</dd>
<dd>Automatically binds event to window resizing</dd>
<dt>v0.4: 14 Jun 2009</dt>
<dd>Better fluid rearrangement support</dd>
<dt>v0.1: Feb 2009</dt>
<dd>Original release</dd>
</dl>
<h2>License</h2>
<p>jQuery Masonry is dual-licensed under <a href="http://www.gnu.org/licenses/gpl.html">GPL</a> and <a href="http://en.wikipedia.org/wiki/MIT_License">MIT</a>, just like <a href="http://docs.jquery.com/License">jQuery itself.</a> You can use it for both personal and commercial applications.</p>
</div>
<p id="footer">
jQuery Masonry by <a href="http://desandro.com/">David DeSandro</a>
</p>
<script type="text/javascript">
$(function(){
$('#secondary').masonry({columnWidth: 100});
})
</script>
</body>
</html>